Skip to content

Commit

Permalink
Merge pull request #24 from thedevdojo/updatesMay2024
Browse files Browse the repository at this point in the history
Fixing URL helper method and cleaning up comments
  • Loading branch information
tnylea committed May 17, 2024
2 parents 9f20ad4 + 7f55fac commit 676f36a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 40 deletions.
6 changes: 5 additions & 1 deletion bin/static
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down
7 changes: 5 additions & 2 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -116,6 +117,8 @@ function buildFile(filePath, buildDir, url){
}
}

content = parser.parseURLs(content, url);

if(content != null){
fs.writeFileSync(filePath, content);
}
Expand Down
9 changes: 6 additions & 3 deletions src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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, () => {
Expand All @@ -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
Expand All @@ -110,6 +110,7 @@ module.exports = {
}

if (contentFile != null) {
contentFile = parser.parseURLs(contentFile, url);
return res.send(contentFile);
}

Expand All @@ -126,6 +127,8 @@ module.exports = {
}

if (pageContent != null) {
pageContent = parser.parseURLs(pageContent, url);

return res.send(pageContent);
}

Expand Down
4 changes: 0 additions & 4 deletions src/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ module.exports = {

});





});
}
}
31 changes: 1 addition & 30 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let env = require('./env.js');
module.exports = {
processFile(filePath, build=false, url='relative') {


let page = this.getPage(filePath);

const layoutTagExists = /<layout[^>]*>[\s\S]*?<\/layout>/.test(page);
Expand All @@ -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;
Expand Down Expand Up @@ -582,34 +581,6 @@ module.exports = {

return jsonData;
}

// processConditions(content, data, parentCollection, loop) {
// // Regular expression to capture the If sections
// const conditionRegex = /<If condition="([^"]+)">([\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 : '';
// });
// }


}

0 comments on commit 676f36a

Please sign in to comment.