test/node_modules/@vuepress/theme-default/lib/client/utils/getAutoLink.js
2024-08-13 09:27:52 +08:00

18 lines
446 B
JavaScript

import { resolveRoute } from 'vuepress/client';
/**
* Resolve AutoLink props from string
*
* @example
* - Input: '/README.md'
* - Output: { text: 'Home', link: '/' }
*/
export const getAutoLink = (config, currentPath) => {
const { notFound, meta, path } = resolveRoute(config, currentPath);
return notFound
? { text: path, link: path }
: {
text: meta.title || path,
link: path,
};
};