From 7f55facd4ffb0291e48de07629fbeb689eb8a35d Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Fri, 17 May 2024 15:14:41 -0400 Subject: [PATCH] Adding a few updates and fixes --- bin/static | 6 +++++- src/build.js | 7 +++++-- src/dev.js | 9 ++++++--- src/new.js | 4 ---- src/parser.js | 31 +------------------------------ 5 files changed, 17 insertions(+), 40 deletions(-) diff --git a/bin/static b/bin/static index 4e35082..f28fb0a 100755 --- a/bin/static +++ b/bin/static @@ -26,8 +26,12 @@ if(cmd == 'new'){ } if(cmd == 'dev'){ + let url = 'relative'; + if(arg1 != 'undefined'){ + url = arg1; + } var dev = require('../src/dev.js'); - dev.start(); + dev.start(url); } if(cmd == 'build'){ diff --git a/src/build.js b/src/build.js index f5f1d81..349c2ff 100644 --- a/src/build.js +++ b/src/build.js @@ -3,6 +3,7 @@ const parser = require('./parser.js'); const currentDirectory = process.cwd(); const path = require('path'); const assets = require('./assets.js'); +const url = 'relative'; module.exports = { start(url='relative'){ @@ -52,7 +53,7 @@ function buildPages(pagesDir, buildDir, url) { if (entry.isDirectory()) { const newBuildDir = path.join(buildDir, entry.name); fs.mkdirSync(newBuildDir, { recursive: true }); - buildPages(entryPath, newBuildDir); + buildPages(entryPath, newBuildDir, url); } else if (entry.isFile() && entry.name.endsWith('.html')) { buildFile(entryPath, buildDir, url); } @@ -71,7 +72,7 @@ function buildContentPages(contentDir, buildDir, url){ if (entry.isDirectory()) { const newBuildDir = path.join(buildDir, entry.name); fs.mkdirSync(newBuildDir, { recursive: true }); - buildContentPages(entryPath, newBuildDir); + buildContentPages(entryPath, newBuildDir, url); } else if (entry.isFile() && entry.name.endsWith('.md')) { buildFile(entryPath, buildDir, url); } @@ -116,6 +117,8 @@ function buildFile(filePath, buildDir, url){ } } + content = parser.parseURLs(content, url); + if(content != null){ fs.writeFileSync(filePath, content); } diff --git a/src/dev.js b/src/dev.js index 86f910d..89c4281 100644 --- a/src/dev.js +++ b/src/dev.js @@ -18,7 +18,7 @@ const globalModulesPath = require("global-modules-path"); const esbuild = require('esbuild'); module.exports = { - start(moveAssets = true){ + start(url='relative', moveAssets = true){ if(moveAssets){ assets.buildJSFile(); assets.moveImages(); @@ -73,7 +73,7 @@ module.exports = { app.use('/', express.static(path.join(currentDirectory, 'public/'))) app.get('/*', (req, res) => { - return this.handleRequest(req, res); + return this.handleRequest(req, res, url); }); app.listen(availablePort, () => { @@ -95,7 +95,7 @@ module.exports = { }); }, - handleRequest(req, res){ + handleRequest(req, res, url){ const route = req.path === '/' ? '/index' : req.path; // First we are going to check if we have a content file in this location @@ -110,6 +110,7 @@ module.exports = { } if (contentFile != null) { + contentFile = parser.parseURLs(contentFile, url); return res.send(contentFile); } @@ -126,6 +127,8 @@ module.exports = { } if (pageContent != null) { + pageContent = parser.parseURLs(pageContent, url); + return res.send(pageContent); } diff --git a/src/new.js b/src/new.js index a0babb2..6d0b4a7 100644 --- a/src/new.js +++ b/src/new.js @@ -73,10 +73,6 @@ module.exports = { }); - - - - }); } } \ No newline at end of file diff --git a/src/parser.js b/src/parser.js index 6085aee..0f5283c 100644 --- a/src/parser.js +++ b/src/parser.js @@ -10,6 +10,7 @@ let env = require('./env.js'); module.exports = { processFile(filePath, build=false, url='relative') { + let page = this.getPage(filePath); const layoutTagExists = /]*>[\s\S]*?<\/layout>/.test(page); @@ -33,8 +34,6 @@ module.exports = { page = this.processCollectionLoops(this.processContentLoops(this.parseShortCodes(this.replaceAttributesInLayout(layout, layoutAttributes), url, build), filePath), filePath); page = this.processCollectionJSON(page); - - page = this.parseURLs(page, url); } return page; @@ -582,34 +581,6 @@ module.exports = { return jsonData; } - - // processConditions(content, data, parentCollection, loop) { - // // Regular expression to capture the If sections - // const conditionRegex = /([\s\S]*?)<\/If>/g; - - // return content.replace(conditionRegex, (match, condition, body) => { - // // Convert placeholder {collectionName.key} into JavaScript context variables - // condition = condition.replace(/{([^}]+)\.([^}]+)}/g, (m, collection, key) => { - // if (collection === parentCollection && typeof data[key] === 'string') { - // return JSON.stringify(data[key]); // Ensure strings are properly escaped - // } else if (collection === parentCollection) { - // return data[key]; - // } - // return m; // If the collection doesn't match, don't replace. - // }); - - // let meetsCondition = false; - - // // Evaluate the condition expression using eval() - // try { - // meetsCondition = eval(condition); - // } catch (err) { - // console.warn(`Failed to evaluate condition: ${condition}`, err); - // } - - // return meetsCondition ? body : ''; - // }); - // } } \ No newline at end of file