Add getRelativeLink

This commit is contained in:
prototypa
2022-11-22 12:47:52 -05:00
parent 5f080b9e6a
commit 87895be803

View File

@ -4,7 +4,7 @@ import { SITE, BLOG } from '~/config.mjs';
const trim = (str, ch) => {
let start = 0,
end = str.length;
end = str.length || 0;
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;
@ -42,20 +42,22 @@ export const getPermalink = (slug = '', type = 'page') => {
case 'post':
return createPath(basePathname, POST_BASE, _slug);
case 'raw':
return createPath(basePathname, trimSlash(slug));
case 'page':
default:
return createPath(basePathname, _slug);
}
};
/** */
export const getBlogPermalink = () => getPermalink(BLOG_BASE);
/** */
export const getHomePermalink = () => {
const permalink = getPermalink();
return permalink !== '/' ? permalink + '/' : permalink;
};
/** */
export const getRelativelink = (link = "") => {
return createPath(basePathname, trimSlash(link));
}
/** */
export const getBlogPermalink = () => getPermalink(BLOG_BASE);