Чистые URL для кейсов: cases/slug/ вместо cases/slug.html, исправлены пути к ассетам
This commit is contained in:
1 parent
c66b9b856f
commit
c4bfe5c9ee
43 files changed
+10703
-10489
No files matched your search
+23
-9
@@ -66,8 +66,9 @@ function ensureDir(dirPath) {
|
||||
/** На странице кейса убираем из HTML карусели карточку со ссылкой на текущий файл (href уже с подставленным casesPrefix). */
|
||||
function stripCurrentCasePortfolioCarouselItem(html, omitHrefBasename) {
|
||||
if (!omitHrefBasename) return html;
|
||||
const hrefDouble = `href="${omitHrefBasename}"`;
|
||||
const hrefSingle = `href='${omitHrefBasename}'`;
|
||||
const slug = omitHrefBasename.replace(/\.html$/, "");
|
||||
const hrefDouble = `href="${slug}/"`;
|
||||
const hrefSingle = `href='${slug}/'`;
|
||||
const itemClass = "projects-carousel__item";
|
||||
let search = 0;
|
||||
while (true) {
|
||||
@@ -98,19 +99,32 @@ function build() {
|
||||
|
||||
for (const pagePath of pageFiles) {
|
||||
const rel = path.relative(srcPagesDir, pagePath);
|
||||
const outPath = path.join(outDir, rel);
|
||||
const relNorm = rel.split(path.sep).join("/");
|
||||
const pageDirRel = path.dirname(rel);
|
||||
const depth = pageDirRel === "." ? 0 : pageDirRel.split(path.sep).length;
|
||||
const isCase = relNorm.startsWith("cases/");
|
||||
|
||||
const vars = {
|
||||
assetPrefix: depth === 0 ? "" : "../".repeat(depth),
|
||||
casesPrefix: depth === 0 ? "cases/" : "",
|
||||
};
|
||||
let outPath;
|
||||
let vars;
|
||||
|
||||
if (isCase) {
|
||||
const slug = path.basename(pagePath, ".html");
|
||||
outPath = path.join(outDir, "cases", slug, "index.html");
|
||||
vars = {
|
||||
assetPrefix: "../../",
|
||||
casesPrefix: "../",
|
||||
};
|
||||
} else {
|
||||
outPath = path.join(outDir, rel);
|
||||
vars = {
|
||||
assetPrefix: depth === 0 ? "" : "../".repeat(depth),
|
||||
casesPrefix: depth === 0 ? "cases/" : "",
|
||||
};
|
||||
}
|
||||
|
||||
const source = readUtf8(pagePath);
|
||||
let rendered = renderTemplate(source, partials, vars);
|
||||
const relNorm = rel.split(path.sep).join("/");
|
||||
if (relNorm.startsWith("cases/")) {
|
||||
if (isCase) {
|
||||
const omitFile = path.basename(pagePath);
|
||||
rendered = stripCurrentCasePortfolioCarouselItem(rendered, omitFile);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user