1- import { glob , readFile , readdir , unlink , writeFile } from "fs/promises"
2- import { join } from "path"
1+ import { glob , readFile , readdir , unlink , writeFile } from "fs/promises" ;
2+ import { join } from "path" ;
3+
4+
5+
6+ import type { Browser } from "playwright" ;
7+
8+
9+
10+ import { ARCHIVE_DIR , HOOK_SCRIPT , SCRIPT , ZIP_SCRIPT } from "./constants.js" ;
11+
12+
313
4- import type { Browser } from "playwright"
514
6- import { ARCHIVE_DIR , HOOK_SCRIPT , SCRIPT , ZIP_SCRIPT } from "./constants.js"
715
816export async function getGeminiIdsFromMarkdowns ( ) : Promise < Set < string > > {
917 const ids = new Set < string > ( )
@@ -97,13 +105,36 @@ export async function archiveConversation(browser: Browser, id: string) {
97105 removeFrames : true ,
98106 insertSingleFileComment : true
99107 } )
100- const fileContent = pageData . content . replaceAll ( / @ f o n t - f a c e \s * { [ ^ } ] * } / g, ( fontFaceRule : string ) => {
101- const fontFamilyMatch = fontFaceRule . match ( / f o n t - f a m i l y : \s * (?< quote > [ ' " ] ? ) (?< fontFamily > [ ^ ' " ] + ) \k<quote > / )
102- const fontFamily = fontFamilyMatch ?. groups ?. [ "fontFamily" ] ?. trim ( ) ?? ""
103108
104- if ( includesKatex && fontFamily . startsWith ( "KaTeX" ) ) return fontFaceRule
105- else return ""
106- } )
109+ const variablesUsedInDocument = new Set (
110+ // Variable values could contain other values, so /var\(([^\)]+)/g won't work
111+ // e.g. --a: var(--b, var(--c));
112+ Array . from ( pageData . content . matchAll ( / v a r \s * \( \s * (?< variableName > - - [ a - z A - z 0 - 9 \- ] + ) / g) ) . map (
113+ regExpExecArray => regExpExecArray . groups ! [ "variableName" ] !
114+ )
115+ )
116+
117+ const fileContent = pageData . content
118+ // Remove Google Sans family and Google Symbol font face
119+ . replaceAll ( / @ f o n t - f a c e \s * { [ ^ } ] * } / g, ( fontFaceRule : string ) => {
120+ const fontFamilyMatch = fontFaceRule . match ( / f o n t - f a m i l y : \s * (?< quote > [ ' " ] ? ) (?< fontFamily > [ ^ ' " ] + ) \k<quote > / )
121+ const fontFamily = fontFamilyMatch ?. groups ?. [ "fontFamily" ] ?. trim ( ) ?? ""
122+
123+ if ( includesKatex && fontFamily . startsWith ( "KaTeX" ) ) return fontFaceRule
124+ else return ""
125+ } )
126+ . replaceAll (
127+ // --a: 0px; } .class { ...
128+ // <div style="--a: 0px"> ...
129+ // <div style='--a: 0px'> ...
130+ / (?< variableName > - - [ a - z A - Z 0 - 9 \- ] + ) \s * : \s * (?< value > [ ^ ; \n \} ] + ) \s * [ ; \n ] ? (?< curlyBrace > \} ) ? (?< quote > [ " ' ] ) ? / gm,
131+ ( _match , variableName : string , value : string , curlyBrace : string | undefined , quote : string | undefined ) => {
132+ const suffix = `${ curlyBrace ?? "" } ${ quote ?? "" } `
133+ console . log ( _match , suffix )
134+ if ( variablesUsedInDocument . has ( variableName ) ) return `${ variableName } :${ value } ;${ suffix } `
135+ return suffix
136+ }
137+ )
107138
108139 // Remove illegal filename chars
109140 const sanitizedTitle = title . replace ( / [ \\ / : * ? " < > | \n ] / g, "" ) . substring ( 0 , 100 )
@@ -126,4 +157,4 @@ export function buildCommitMessage(added: string[], deleted: string[]): string {
126157 if ( deleted . length > 0 ) msg += `\nDeleted conversations: ${ deleted . join ( ", " ) } `
127158
128159 return msg
129- }
160+ }
0 commit comments