From e651f2eb6a5ffda63995b53ef03b9b3afb0f3f36 Mon Sep 17 00:00:00 2001 From: tfmukles Date: Tue, 3 Dec 2024 15:17:31 +0600 Subject: [PATCH] Update hugo.toml baseURL and modify projectSetup.js and themeSetup.js scripts to toggle baseURL value --- exampleSite/hugo.toml | 2 +- scripts/projectSetup.js | 9 +++++++++ scripts/themeSetup.js | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/exampleSite/hugo.toml b/exampleSite/hugo.toml index 5de3020..055fc75 100755 --- a/exampleSite/hugo.toml +++ b/exampleSite/hugo.toml @@ -1,6 +1,6 @@ ######################## default configuration #################### # The base URL of your site (required). This will be prepended to all relative URLs. -baseURL = "/" +baseURL = "https://example.org" # Title of your website (required). title = "Hugoplate" # Your theme name diff --git a/scripts/projectSetup.js b/scripts/projectSetup.js index 5b92703..d2779b0 100644 --- a/scripts/projectSetup.js +++ b/scripts/projectSetup.js @@ -5,6 +5,13 @@ const toggleComment = ({ filepath, regex }) => { let updatedContent = fs.readFileSync(filepath, "utf8"); const match = updatedContent.match(regex); + if (filepath.endsWith("hugo.toml")) { + updatedContent = updatedContent.replace( + 'baseURL = "https://example.org"', + 'baseURL = "/"', + ); + } + if (match) { const matchedContent = match[0]; const hasComment = matchedContent.startsWith("# "); @@ -110,6 +117,8 @@ const setupProject = () => { const exampleSite = path.join(rootFolder, "exampleSite"); iterateFilesAndFolders(exampleSite, { destinationRoot: rootFolder }); deleteFolder(exampleSite); + } else { + console.log("Project already setup"); } }; diff --git a/scripts/themeSetup.js b/scripts/themeSetup.js index 28a697a..a21bd6c 100644 --- a/scripts/themeSetup.js +++ b/scripts/themeSetup.js @@ -5,6 +5,13 @@ const toggleComment = ({ filepath, regex }) => { let updatedContent = fs.readFileSync(filepath, "utf8"); const match = updatedContent.match(regex); + if (filepath.endsWith("hugo.toml")) { + updatedContent = updatedContent.replace( + 'baseURL = "/"', + 'baseURL = "https://example.org"', + ); + } + if (match) { const matchedContent = match[0]; const hasComment = matchedContent.startsWith("# ");