11import fs from "node:fs" ;
22import path from "node:path" ;
3- import type { ISynctexBlockId , Metadata } from "@fluffylabs/links-metadata" ;
3+ import type { INoteV3 , INotesEnvelopeV3 , Metadata } from "@fluffylabs/links-metadata" ;
44import { fetchMetadata , findLink , parseLink } from "@fluffylabs/links-metadata" ;
55
66/**
77 * Convert messages.json file generated by the tool into Reader notes format
88 * so it can be imported or loaded as remote content.
99 */
10-
1110type Message = {
1211 /** ISO date. */
1312 date : string ;
@@ -19,31 +18,6 @@ type Message = {
1918 msg : string ;
2019} ;
2120
22- // TODO [ToDr] Note these types could be shared between the `matrix-bot`
23- // and the reader, however since we want to avoid having too many shared
24- // packages (to simplify publishing to npm) and this type does not really
25- // fit the `links-metadata`, I've decided to duplicate it here.
26- // Note it's a historical format, so it SHOULD NOT change anyway.
27- type NoteV3 = {
28- noteVersion : 3 ;
29- content : string ;
30- /** local-tz timestamp (from Date.now()) */
31- date : number ;
32- /** empty for local notes. */
33- author : string ;
34- /** Full version number. */
35- version : string ;
36- /** Labels. */
37- labels : string [ ] ;
38-
39- selectionStart : ISynctexBlockId ;
40- selectionEnd : ISynctexBlockId ;
41- } ;
42- type INotesEnvelopeV3 = {
43- version : 3 ;
44- notes : NoteV3 [ ] ;
45- } ;
46-
4721async function main ( file = "./output/messages.json" ) {
4822 const content = fs . readFileSync ( path . resolve ( file ) , "utf-8" ) ;
4923 // note that the file is not a valid JSON as-is (it's appended to),
@@ -54,7 +28,7 @@ async function main(file = "./output/messages.json") {
5428 // get metadata and synctex data.
5529 const meta = await fetchMetadata ( ) ;
5630
57- const notes = new Map < string , NoteV3 > ( ) ;
31+ const notes = new Map < string , INoteV3 > ( ) ;
5832 for ( const msg of data ) {
5933 const linkData = await findAndParseLink ( msg . msg , meta ) ;
6034 if ( linkData === null ) {
0 commit comments