From 1483474507a76a10205c45185ec813a1addb1cdd Mon Sep 17 00:00:00 2001 From: Josh Padnick Date: Tue, 13 May 2025 16:05:10 -0700 Subject: [PATCH 1/8] Write files locally to test output --- scripts/sync-legal-pages.js | 98 ++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 18 deletions(-) diff --git a/scripts/sync-legal-pages.js b/scripts/sync-legal-pages.js index bac92bb..77a37d4 100644 --- a/scripts/sync-legal-pages.js +++ b/scripts/sync-legal-pages.js @@ -40,22 +40,66 @@ const md = new MarkdownIt({ html: true // Enable HTML tags in source }); -// Function to preprocess markdown content to handle special comments -function preprocessMarkdown(content) { - debugLog('Preprocessing markdown content'); - - // Replace "Plain English" comment blocks with a custom div - const processedContent = content.replace( - //g, - (_, plainEnglishContent) => { - // Trim whitespace and create a proper HTML section that won't be escaped - const cleanContent = plainEnglishContent.trim(); - return `\n\n
Plain English: ${cleanContent}
\n\n`; +// Function to parse markdown into sections of Plain English and Legalese +function parseSections(content) { + // Regex to match all Plain English blocks + const regex = //g; + let match; + let lastIndex = 0; + const sections = []; + + while ((match = regex.exec(content)) !== null) { + const plainEnglish = match[1].trim(); + const start = match.index; + const end = regex.lastIndex; + + // Legalese is the text between the end of the last match and the start of this match + if (start > lastIndex) { + const legalese = content.slice(lastIndex, start).trim(); + if (sections.length > 0) { + // Attach legalese to previous section + sections[sections.length - 1].legalese += '\n' + legalese; + } else if (legalese) { + // If legalese comes before any Plain English, add as its own section + sections.push({ plainEnglish: '', legalese }); + } + } + // Start a new section with this Plain English + sections.push({ plainEnglish, legalese: '' }); + lastIndex = end; + } + // Add any trailing legalese after the last Plain English + if (lastIndex < content.length) { + const legalese = content.slice(lastIndex).trim(); + if (sections.length > 0) { + sections[sections.length - 1].legalese += '\n' + legalese; + } else if (legalese) { + sections.push({ plainEnglish: '', legalese }); } - ); + } + return sections; +} - debugLog('Markdown preprocessing complete'); - return processedContent; +// Function to generate side-by-side HTML layout for sections +function generateHtmlLayout(sections) { + // Use a container and grid/flex rows for each section + let html = ''; + return html; } // Initialize the Webflow client @@ -278,16 +322,34 @@ async function syncWebflow() { const markdownContent = fs.readFileSync(filePath, 'utf8'); debugLog(`Read ${markdownContent.length} characters from file`); - debugLog('Preprocessing markdown and converting to HTML'); - const processedMarkdown = preprocessMarkdown(markdownContent); - const htmlContent = md.render(processedMarkdown); + debugLog('Parsing sections and generating side-by-side HTML layout'); + const sections = parseSections(markdownContent); + const htmlContent = generateHtmlLayout(sections); debugLog(`Generated ${htmlContent.length} characters of HTML`); const title = extractTitle(filePath); const repoPath = filePath; // The path relative to the repo root + // Write HTML content to disk for debugging/review + const htmlOutputPath = path.join('scripts', 'output', path.dirname(filePath), `${path.basename(filePath, '.md')}.html`); + debugLog(`Writing HTML output to: ${htmlOutputPath}`); + + // Read header and footer templates + const headerContent = fs.readFileSync(path.join('scripts', 'input', 'header.html'), 'utf8'); + const footerContent = fs.readFileSync(path.join('scripts', 'input', 'footer.html'), 'utf8'); + + // Combine header, content and footer + const fullHtmlContent = headerContent + htmlContent + footerContent; + + // Ensure the output directory exists + fs.mkdirSync(path.dirname(htmlOutputPath), { recursive: true }); + + // Write the HTML content to file + fs.writeFileSync(htmlOutputPath, fullHtmlContent); + debugLog(`Successfully wrote HTML to ${htmlOutputPath}`); + debugLog(`Syncing item with title: "${title}", path: "${repoPath}"`); - await syncItem(repoPath, markdownContent, htmlContent, title, existingItemsMap); + //await syncItem(repoPath, markdownContent, htmlContent, title, existingItemsMap); } catch (fileProcessingError) { console.error(`Error processing file ${filePath}:`, fileProcessingError.message); From 51f66a69e8647435cde8bd87329726506cc40dfe Mon Sep 17 00:00:00 2001 From: Josh Padnick Date: Tue, 13 May 2025 16:12:08 -0700 Subject: [PATCH 2/8] Extract local write function --- scripts/sync-legal-pages.js | 42 ++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/scripts/sync-legal-pages.js b/scripts/sync-legal-pages.js index 77a37d4..47af68e 100644 --- a/scripts/sync-legal-pages.js +++ b/scripts/sync-legal-pages.js @@ -286,6 +286,26 @@ async function syncItem(repoPath, mdContent, htmlContent, title, existingItemsMa } } +// Good for debugging; write the HTML to a file for review +function writeHtmlToFile(filePath, htmlContent) { + const htmlOutputPath = path.join('scripts', 'output', path.dirname(filePath), `${path.basename(filePath, '.md')}.html`); + debugLog(`Writing HTML output to: ${htmlOutputPath}`); + + // Read header and footer templates + const headerContent = fs.readFileSync(path.join('scripts', 'input', 'header.html'), 'utf8'); + const footerContent = fs.readFileSync(path.join('scripts', 'input', 'footer.html'), 'utf8'); + + // Combine header, content and footer + const fullHtmlContent = headerContent + htmlContent + footerContent; + + // Ensure the output directory exists + fs.mkdirSync(path.dirname(htmlOutputPath), { recursive: true }); + + // Write the HTML content to file + fs.writeFileSync(htmlOutputPath, fullHtmlContent); + debugLog(`Successfully wrote HTML to ${htmlOutputPath}`); +} + // Main sync function async function syncWebflow() { debugLog('Starting Webflow sync process'); @@ -330,25 +350,9 @@ async function syncWebflow() { const title = extractTitle(filePath); const repoPath = filePath; // The path relative to the repo root - // Write HTML content to disk for debugging/review - const htmlOutputPath = path.join('scripts', 'output', path.dirname(filePath), `${path.basename(filePath, '.md')}.html`); - debugLog(`Writing HTML output to: ${htmlOutputPath}`); - - // Read header and footer templates - const headerContent = fs.readFileSync(path.join('scripts', 'input', 'header.html'), 'utf8'); - const footerContent = fs.readFileSync(path.join('scripts', 'input', 'footer.html'), 'utf8'); - - // Combine header, content and footer - const fullHtmlContent = headerContent + htmlContent + footerContent; - - // Ensure the output directory exists - fs.mkdirSync(path.dirname(htmlOutputPath), { recursive: true }); - - // Write the HTML content to file - fs.writeFileSync(htmlOutputPath, fullHtmlContent); - debugLog(`Successfully wrote HTML to ${htmlOutputPath}`); - - debugLog(`Syncing item with title: "${title}", path: "${repoPath}"`); + writeHtmlToFile(filePath, htmlContent); + + //debugLog(`Syncing item with title: "${title}", path: "${repoPath}"`); //await syncItem(repoPath, markdownContent, htmlContent, title, existingItemsMap); } catch (fileProcessingError) { From d027a24d0b53898ec4761a758704b409c10a4a41 Mon Sep 17 00:00:00 2001 From: Josh Padnick Date: Tue, 13 May 2025 16:22:25 -0700 Subject: [PATCH 3/8] Add separate column for plain English --- scripts/sync-legal-pages.js | 50 ++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/scripts/sync-legal-pages.js b/scripts/sync-legal-pages.js index 47af68e..34b83ce 100644 --- a/scripts/sync-legal-pages.js +++ b/scripts/sync-legal-pages.js @@ -82,18 +82,22 @@ function parseSections(content) { // Function to generate side-by-side HTML layout for sections function generateHtmlLayout(sections) { - // Use a container and grid/flex rows for each section + // Render each section as a row with two columns, aligned vertically let html = '