Fix minimal details

This commit is contained in:
prototypa
2022-09-04 00:56:24 -04:00
parent 570cf904c4
commit 1cf25d6b43
44 changed files with 757 additions and 641 deletions

View File

@ -1,17 +1,17 @@
import slugify from 'limax';
import slugify from "limax";
import { SITE, BLOG } from "~/config.mjs";
const trim = (str, ch) => {
let start = 0, end = str.length;
while(start < end && str[start] === ch)
++start;
while(end > start && str[end - 1] === ch)
--end;
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
}
let start = 0,
end = str.length;
while (start < end && str[start] === ch) ++start;
while (end > start && str[end - 1] === ch) --end;
return start > 0 || end < str.length ? str.substring(start, end) : str;
};
const trimSlash = (s) => trim(trim(s, "/"));
const createPath = (...params) => "/" + params.filter((el) => !!el).join("/")
const createPath = (...params) => "/" + params.filter((el) => !!el).join("/");
const basePathname = trimSlash(SITE.basePathname);
@ -21,17 +21,19 @@ export const BLOG_BASE = cleanSlug(BLOG.slug);
export const CATEGORY_BASE = cleanSlug(BLOG?.category?.slug);
export const TAG_BASE = cleanSlug(BLOG?.tag?.slug);
/** */
export const getCanonical = (path = "") => new URL(path, SITE.origin);
/** */
export const getPermalink = (slug = "", type = "page") => {
const _slug = cleanSlug(slug);
switch (type) {
case "category":
return createPath(basePathname, CATEGORY_BASE, _slug)
return createPath(basePathname, CATEGORY_BASE, _slug);
case "tag":
return createPath(basePathname, TAG_BASE, _slug)
return createPath(basePathname, TAG_BASE, _slug);
case "post":
return createPath(basePathname, BLOG.postsWithoutBlogSlug ? "" : BLOG_BASE, _slug);
@ -42,8 +44,11 @@ export const getPermalink = (slug = "", type = "page") => {
}
};
/** */
export const getBlogPermalink = () => getPermalink(BLOG_BASE);
/** */
export const getHomePermalink = () => {
const permalink = getPermalink();
return permalink !== "/" ? permalink + "/" : permalink;
}
};