Skip to content

Commit

Permalink
Test simpler kebabifying
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Aug 20, 2024
1 parent 8000e0d commit 23c12e6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/build/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { PathInfo } from "../lib/paths.mjs";
import { CONTENT_TYPES } from "./partition-content.mjs";
// Direct importing of JSON files isn't supported yet in ES modules. This is a workaround.
import { createRequire } from "module";
import kebabCase from "lodash.kebabcase";

const require = createRequire(import.meta.url);
const CONFIG = require("../../config.json");
Expand Down Expand Up @@ -42,6 +41,14 @@ if (code) {
process.exitCode = code;
}

function formatURLPart(str) {
// Defines formatting of URL parts for static content staging
return str
.replace(/([a-z])([A-Z])/g, "$1-$2")
// .replace(/_/g, "-") (test w/o underscore to kebab)
.toLowerCase();
}

// Stage static files, standardizing to kebab-lowercase paths but leaving filenames alone
function stageStaticContent(srcDir, destDir) {
// Build glob pattern from defined copyFileExts (image, mov, etc. extensions)
Expand All @@ -58,7 +65,7 @@ function stageStaticContent(srcDir, destDir) {

// break part path, map kebab-case, and rejoin
const parts = filePath.split(path.sep);
const kebabParts = parts.map((part) => kebabCase(part));
const kebabParts = parts.map((part) => formatURLPart(part));
const kebabPath = kebabParts.join(path.sep);

const destPath = path.join(destDir, kebabPath, fileName);
Expand Down

0 comments on commit 23c12e6

Please sign in to comment.