Add getRelativeLink
This commit is contained in:
@ -4,7 +4,7 @@ import { SITE, BLOG } from '~/config.mjs';
|
|||||||
|
|
||||||
const trim = (str, ch) => {
|
const trim = (str, ch) => {
|
||||||
let start = 0,
|
let start = 0,
|
||||||
end = str.length;
|
end = str.length || 0;
|
||||||
while (start < end && str[start] === ch) ++start;
|
while (start < end && str[start] === ch) ++start;
|
||||||
while (end > start && str[end - 1] === ch) --end;
|
while (end > start && str[end - 1] === ch) --end;
|
||||||
return start > 0 || end < str.length ? str.substring(start, end) : str;
|
return start > 0 || end < str.length ? str.substring(start, end) : str;
|
||||||
@ -42,20 +42,22 @@ export const getPermalink = (slug = '', type = 'page') => {
|
|||||||
case 'post':
|
case 'post':
|
||||||
return createPath(basePathname, POST_BASE, _slug);
|
return createPath(basePathname, POST_BASE, _slug);
|
||||||
|
|
||||||
case 'raw':
|
|
||||||
return createPath(basePathname, trimSlash(slug));
|
|
||||||
|
|
||||||
case 'page':
|
case 'page':
|
||||||
default:
|
default:
|
||||||
return createPath(basePathname, _slug);
|
return createPath(basePathname, _slug);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** */
|
|
||||||
export const getBlogPermalink = () => getPermalink(BLOG_BASE);
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
export const getHomePermalink = () => {
|
export const getHomePermalink = () => {
|
||||||
const permalink = getPermalink();
|
const permalink = getPermalink();
|
||||||
return permalink !== '/' ? permalink + '/' : permalink;
|
return permalink !== '/' ? permalink + '/' : permalink;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** */
|
||||||
|
export const getRelativelink = (link = "") => {
|
||||||
|
return createPath(basePathname, trimSlash(link));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
export const getBlogPermalink = () => getPermalink(BLOG_BASE);
|
||||||
|
Reference in New Issue
Block a user