-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
636 additions
and
295 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Internal modules | ||
import { cp, rm } from "node:fs/promises" | ||
|
||
// Helper functions | ||
import { ensureFoldersExist } from "./helpers/ensureFoldersExist.js" | ||
import { removeEmptyFolders } from "./helpers/removeEmptyFolders.js" | ||
import { copyStaticFolderWithFilters } from "./helpers/copyStaticFolderWithFilters.js" | ||
|
||
// Settings | ||
import { settings } from "../../config/settings.js" | ||
|
||
// Routes | ||
import { archiveRoute } from "./routes/archiveRoute.js" | ||
import { mainRoute } from "./routes/mainRoute.js" | ||
import { markdownRoute } from "./routes/markdownRoute.js" | ||
import { rssRoute } from "./routes/rssRoute.js" | ||
import { searchRoute } from "./routes/searchRoute.js" | ||
import { sitemapRoute } from "./routes/sitemapRoute.js" | ||
import { tagRoute } from "./routes/tagRoute.js" | ||
import { tagsRoute } from "./routes/tagsRoute.js" | ||
|
||
/** | ||
* Function to generate a static site | ||
* ================================== | ||
*/ | ||
async function build() { | ||
try { | ||
// Remove admin link from menu | ||
delete settings.menuLinks.admin | ||
|
||
// Remove existing "_site" directory if it exists | ||
await rm("_site", { recursive: true, force: true }) | ||
|
||
// Ensure necessary folders exist | ||
await ensureFoldersExist([ | ||
"_site/page", | ||
"_site/pages", | ||
"_site/posts", | ||
"_site/templates", | ||
"_site/tags", | ||
"_site/search", | ||
"_site/static", | ||
]) | ||
|
||
// Copy "static" folder to "_site/static" with filter function | ||
await cp("static", "_site/static", { recursive: true, filter: copyStaticFolderWithFilters }) | ||
|
||
// Execute the route creation functions | ||
markdownRoute() | ||
mainRoute() | ||
archiveRoute() | ||
tagsRoute() | ||
tagRoute() | ||
rssRoute() | ||
sitemapRoute() | ||
settings.searchFeature ? searchRoute() : delete settings.menuLinks.search | ||
|
||
// Remove empty folders at the end of a build | ||
await removeEmptyFolders("_site") | ||
} catch (error) { | ||
console.error("Build error:", error) | ||
} | ||
} | ||
|
||
// Run the build function | ||
build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { normalize } from "node:path" | ||
import { settings } from "../../../config/settings.js" | ||
|
||
/** | ||
* Helper function to filter the copy of "static" into "_site/static". | ||
* =================================================================== | ||
* | ||
* @param {string} src - The path to the source "static" folder. | ||
* @param {string} dest - The path to the destination "_site/static" folder. | ||
*/ | ||
export const copyStaticFolderWithFilters = async (src, dest) => { | ||
try { | ||
const normalizedSrc = normalize(src) | ||
|
||
// Exclude paths ending with "admin" or "dump" and their contents | ||
if (normalizedSrc.endsWith("admin")) { | ||
return false // Exclude this path | ||
} | ||
|
||
// Include only the "currentTheme" folder within the "themes" folder | ||
if (normalizedSrc.includes("themes") && !normalizedSrc.endsWith("themes")) { | ||
if (normalizedSrc.includes(settings.currentTheme)) { | ||
return true // Include this path (the "currentTheme" folder) | ||
} else { | ||
return false // Exclude other paths within "themes" | ||
} | ||
} | ||
|
||
// Include all other files/folders | ||
return true | ||
} catch (error) { | ||
console.error(`Error in copyStaticFolderWithFilters: ${error.message}`) | ||
throw error | ||
} | ||
} |
Oops, something went wrong.