* [packages][m]: mv @flowershow/core package here * [packages/core][xs]: rename to @portaljs/core * [package.json][xs]: setup npm workspaces * [packages/core][xs]:replace deprecated rollup executor * [core/package.json][s]: fix mermaid versions * [core/tsconfig][xs]: rm extends * [core/jest.config][xs]: rm coverageDirectory * [core/package.json][xs]: install core-js * [packages.json][s]:use same version for all nrwl packages * [core/.eslintrc][xs]: adjust ignorePatterns * [core/project.json][xs]: rm publish targets * [packages][m]: mv @flowershow/remark-wiki-link here * [packages][m]: mv @flowershow/remark-wiki-link here * [packages][m]: mv @flowershow/remark-embed here * [remark-callouts/project.json][xs]: adjst test pattern * [package.json][s]: install missing deps * [remark-callouts][xs]: adjst fields in package.json * [remark-callouts][s]: rm pubish targets and adjst build executor * [remark-embed/jest.config][xs]: rm unknown option coverageDirectory * [remark-embed][xs]: rm publish targets * [remark-embed][s]: rename to @portaljs/remark-embed * [remark-wiki-link/eslintrc][xs]:adjst ignorePatterns * [package.json][xs]: install missing deps * [remark-wiki-link/test][xs]:specify format - also temporarily force any type on htmlExtension * [remark-wiki-link/README][xs]: replace @flowershow with @portaljs * [remark-wiki-link][xs]:rm old changelog * [remark-wiki-link][xs]: adjst package.json * [remark-wiki-link/project.json][xs]: rm publish targets * [core][s]: rm old changelog * [core/README][xs]:correct scope name * [remark-callouts/README][xs]: add @portaljs to pckg name * [remark-embed/README][xs]: add @portaljs to pckg name * [package-lock.json][xs]: refresh after rebasing on main
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import * as path from "path";
|
|
// import * as url from "url";
|
|
import { getPermalinks } from "../src/utils";
|
|
|
|
// const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
// const markdownFolder = path.join(__dirname, "/fixtures/content");
|
|
const markdownFolder = path.join(
|
|
".",
|
|
"/packages/remark-wiki-link/test/fixtures/content"
|
|
);
|
|
|
|
describe("getPermalinks", () => {
|
|
test("should return an array of permalinks", () => {
|
|
const expectedPermalinks = [
|
|
"/", // /index.md
|
|
"/abc",
|
|
"/blog/first-post",
|
|
"/blog/Second Post",
|
|
"/blog/third-post",
|
|
"/blog", // /blog/index.md
|
|
"/blog/tutorials/first-tutorial",
|
|
"/assets/Pasted Image 123.png",
|
|
];
|
|
|
|
const permalinks = getPermalinks(markdownFolder, [/\.DS_Store/]);
|
|
expect(permalinks).toHaveLength(expectedPermalinks.length);
|
|
permalinks.forEach((permalink) => {
|
|
expect(expectedPermalinks).toContain(permalink);
|
|
});
|
|
});
|
|
|
|
test("should return an array of permalinks with custom path -> permalink converter function", () => {
|
|
const expectedPermalinks = [
|
|
"/", // /index.md
|
|
"/abc",
|
|
"/blog/first-post",
|
|
"/blog/second-post",
|
|
"/blog/third-post",
|
|
"/blog", // /blog/index.md
|
|
"/blog/tutorials/first-tutorial",
|
|
"/assets/pasted-image-123.png",
|
|
];
|
|
|
|
const func = (filePath: string, markdownFolder: string) => {
|
|
const permalink = filePath
|
|
.replace(markdownFolder, "") // make the permalink relative to the markdown folder
|
|
.replace(/\.(mdx|md)/, "")
|
|
.replace(/\\/g, "/") // replace windows backslash with forward slash
|
|
.replace(/\/index$/, "") // remove index from the end of the permalink
|
|
.replace(/ /g, "-") // replace spaces with hyphens
|
|
.toLowerCase(); // convert to lowercase
|
|
|
|
return permalink.length > 0 ? permalink : "/"; // for home page
|
|
};
|
|
|
|
const permalinks = getPermalinks(markdownFolder, [/\.DS_Store/], func);
|
|
expect(permalinks).toHaveLength(expectedPermalinks.length);
|
|
permalinks.forEach((permalink) => {
|
|
expect(expectedPermalinks).toContain(permalink);
|
|
});
|
|
});
|
|
});
|