Use Prettier
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
import slugify from "limax";
|
||||
import slugify from 'limax';
|
||||
|
||||
import { SITE, BLOG } from "~/config.mjs";
|
||||
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 trimSlash = (s) => trim(trim(s, '/'));
|
||||
const createPath = (...params) => '/' + params.filter((el) => !!el).join('/');
|
||||
|
||||
const basePathname = trimSlash(SITE.basePathname);
|
||||
|
||||
@ -22,26 +22,26 @@ 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 getCanonical = (path = '') => new URL(path, SITE.origin);
|
||||
|
||||
/** */
|
||||
export const getPermalink = (slug = "", type = "page") => {
|
||||
const _slug = cleanSlug(slug);
|
||||
export const getPermalink = (slug = '', type = 'page') => {
|
||||
const _slug = cleanSlug(slug);
|
||||
|
||||
switch (type) {
|
||||
case "category":
|
||||
return createPath(basePathname, CATEGORY_BASE, _slug);
|
||||
switch (type) {
|
||||
case 'category':
|
||||
return createPath(basePathname, CATEGORY_BASE, _slug);
|
||||
|
||||
case "tag":
|
||||
return createPath(basePathname, TAG_BASE, _slug);
|
||||
case 'tag':
|
||||
return createPath(basePathname, TAG_BASE, _slug);
|
||||
|
||||
case "post":
|
||||
return createPath(basePathname, BLOG.postsWithoutBlogSlug ? "" : BLOG_BASE, _slug);
|
||||
case 'post':
|
||||
return createPath(basePathname, BLOG.postsWithoutBlogSlug ? '' : BLOG_BASE, _slug);
|
||||
|
||||
case "page":
|
||||
default:
|
||||
return createPath(basePathname, _slug);
|
||||
}
|
||||
case 'page':
|
||||
default:
|
||||
return createPath(basePathname, _slug);
|
||||
}
|
||||
};
|
||||
|
||||
/** */
|
||||
@ -49,6 +49,6 @@ export const getBlogPermalink = () => getPermalink(BLOG_BASE);
|
||||
|
||||
/** */
|
||||
export const getHomePermalink = () => {
|
||||
const permalink = getPermalink();
|
||||
return permalink !== "/" ? permalink + "/" : permalink;
|
||||
const permalink = getPermalink();
|
||||
return permalink !== '/' ? permalink + '/' : permalink;
|
||||
};
|
||||
|
Reference in New Issue
Block a user