From 85de6f78784acb3fbc329304d1d9e710a7d7d35b Mon Sep 17 00:00:00 2001
From: Ola Rubaj <52197250+olayway@users.noreply.github.com>
Date: Thu, 9 May 2024 02:08:25 +0200
Subject: [PATCH 1/5] replace inex.md with README.md in test fixtures
---
.../test/fixtures/content/{blog/index.md => README.md} | 0
.../test/fixtures/content/{index.md => blog/README.md} | 0
packages/remark-wiki-link/test/getPermalinks.spec.ts | 7 ++-----
3 files changed, 2 insertions(+), 5 deletions(-)
rename packages/remark-wiki-link/test/fixtures/content/{blog/index.md => README.md} (100%)
rename packages/remark-wiki-link/test/fixtures/content/{index.md => blog/README.md} (100%)
diff --git a/packages/remark-wiki-link/test/fixtures/content/blog/index.md b/packages/remark-wiki-link/test/fixtures/content/README.md
similarity index 100%
rename from packages/remark-wiki-link/test/fixtures/content/blog/index.md
rename to packages/remark-wiki-link/test/fixtures/content/README.md
diff --git a/packages/remark-wiki-link/test/fixtures/content/index.md b/packages/remark-wiki-link/test/fixtures/content/blog/README.md
similarity index 100%
rename from packages/remark-wiki-link/test/fixtures/content/index.md
rename to packages/remark-wiki-link/test/fixtures/content/blog/README.md
diff --git a/packages/remark-wiki-link/test/getPermalinks.spec.ts b/packages/remark-wiki-link/test/getPermalinks.spec.ts
index de916171..6a34ad9c 100644
--- a/packages/remark-wiki-link/test/getPermalinks.spec.ts
+++ b/packages/remark-wiki-link/test/getPermalinks.spec.ts
@@ -1,9 +1,6 @@
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(
".",
"test/fixtures/content"
@@ -12,12 +9,12 @@ const markdownFolder = path.join(
describe("getPermalinks", () => {
test("should return an array of permalinks", () => {
const expectedPermalinks = [
- "/", // /index.md
+ "/README",
"/abc",
"/blog/first-post",
"/blog/Second Post",
"/blog/third-post",
- "/blog", // /blog/index.md
+ "/blog/README",
"/blog/tutorials/first-tutorial",
"/assets/Pasted Image 123.png",
];
From 2ac82367c52b2887a76d293b39b22eeeaa9f205e Mon Sep 17 00:00:00 2001
From: Ola Rubaj <52197250+olayway@users.noreply.github.com>
Date: Thu, 9 May 2024 02:10:10 +0200
Subject: [PATCH 2/5] do not remove "index" from the end of file
- should be treated as a regular file name
- it's up to the app how to interpret those paths/files later
---
.../src/utils/getPermalinks.ts | 1 -
.../test/micromarkExtensionWikiLink.spec.ts | 58 +---------
.../test/remarkWikiLink.spec.ts | 103 ------------------
3 files changed, 4 insertions(+), 158 deletions(-)
diff --git a/packages/remark-wiki-link/src/utils/getPermalinks.ts b/packages/remark-wiki-link/src/utils/getPermalinks.ts
index c3f6a6c9..b2b73149 100644
--- a/packages/remark-wiki-link/src/utils/getPermalinks.ts
+++ b/packages/remark-wiki-link/src/utils/getPermalinks.ts
@@ -38,6 +38,5 @@ const defaultPathToPermalinkFunc = (
.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
return permalink.length > 0 ? permalink : "/"; // for home page
};
diff --git a/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts b/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts
index 5f2f9e8e..da010cdc 100644
--- a/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts
+++ b/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts
@@ -159,11 +159,11 @@ describe("micromark-extension-wiki-link", () => {
});
expect(serialized).toBe(
'

'
- );
- });
-
+ );
+ });
+
// TODO: Fix alt attribute
- test("Can identify the dimensions of the image if exists", () => {
+ test("Can identify the dimensions of the image if exists", () => {
const serialized = micromark("![[My Image.jpg|200x200]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html({ permalinks: ["My Image.jpg"] }) as any], // TODO type fix
@@ -286,56 +286,6 @@ describe("micromark-extension-wiki-link", () => {
});
});
- test("parses wiki links to index files", () => {
- const serialized = micromark("[[/some/folder/index]]", "ascii", {
- extensions: [syntax()],
- htmlExtensions: [html() as any], // TODO type fix
- });
- expect(serialized).toBe(
- '/some/folder/index
'
- );
- });
-
- describe("other", () => {
- test("parses a wiki link to some index page in a folder with no matching permalink", () => {
- const serialized = micromark("[[/some/folder/index]]", "ascii", {
- extensions: [syntax()],
- htmlExtensions: [html() as any], // TODO type fix
- });
- expect(serialized).toBe(
- '/some/folder/index
'
- );
- });
-
- test("parses a wiki link to some index page in a folder with a matching permalink", () => {
- const serialized = micromark("[[/some/folder/index]]", "ascii", {
- extensions: [syntax()],
- htmlExtensions: [html({ permalinks: ["/some/folder"] }) as any], // TODO type fix
- });
- expect(serialized).toBe(
- '/some/folder/index
'
- );
- });
-
- test("parses a wiki link to home index page with no matching permalink", () => {
- const serialized = micromark("[[/index]]", "ascii", {
- extensions: [syntax()],
- htmlExtensions: [html() as any], // TODO type fix
- });
- expect(serialized).toBe(
- '/index
'
- );
- });
-
- test("parses a wiki link to home index page with a matching permalink", () => {
- const serialized = micromark("[[/index]]", "ascii", {
- extensions: [syntax()],
- htmlExtensions: [html({ permalinks: ["/"] }) as any], // TODO type fix
- });
- expect(serialized).toBe('/index
');
- });
- });
-
describe("transclusions", () => {
test("parsers a transclusion as a regular wiki link", () => {
const serialized = micromark("![[Some Page]]", "ascii", {
diff --git a/packages/remark-wiki-link/test/remarkWikiLink.spec.ts b/packages/remark-wiki-link/test/remarkWikiLink.spec.ts
index 051cc42c..72975df0 100644
--- a/packages/remark-wiki-link/test/remarkWikiLink.spec.ts
+++ b/packages/remark-wiki-link/test/remarkWikiLink.spec.ts
@@ -485,109 +485,6 @@ describe("remark-wiki-link", () => {
});
});
- test("parses wiki links to index files", () => {
- const processor = unified().use(markdown).use(wikiLinkPlugin);
-
- let ast = processor.parse("[[/some/folder/index]]");
- ast = processor.runSync(ast);
-
- expect(select("wikiLink", ast)).not.toEqual(null);
-
- visit(ast, "wikiLink", (node: Node) => {
- expect(node.data?.exists).toEqual(false);
- expect(node.data?.permalink).toEqual("/some/folder");
- expect(node.data?.alias).toEqual(null);
- expect(node.data?.hName).toEqual("a");
- expect((node.data?.hProperties as any).className).toEqual("internal new");
- expect((node.data?.hProperties as any).href).toEqual("/some/folder");
- expect((node.data?.hChildren as any)[0].value).toEqual(
- "/some/folder/index"
- );
- });
- });
-
- describe("other", () => {
- test("parses a wiki link to some index page in a folder with no matching permalink", () => {
- const processor = unified().use(markdown).use(wikiLinkPlugin);
-
- let ast = processor.parse("[[/some/folder/index]]");
- ast = processor.runSync(ast);
-
- visit(ast, "wikiLink", (node: Node) => {
- expect(node.data?.exists).toEqual(false);
- expect(node.data?.permalink).toEqual("/some/folder");
- expect(node.data?.alias).toEqual(null);
- expect(node.data?.hName).toEqual("a");
- expect((node.data?.hProperties as any).className).toEqual(
- "internal new"
- );
- expect((node.data?.hProperties as any).href).toEqual("/some/folder");
- expect((node.data?.hChildren as any)[0].value).toEqual(
- "/some/folder/index"
- );
- });
- });
-
- test("parses a wiki link to some index page in a folder with a matching permalink", () => {
- const processor = unified()
- .use(markdown)
- .use(wikiLinkPlugin, { permalinks: ["/some/folder"] });
-
- let ast = processor.parse("[[/some/folder/index]]");
- ast = processor.runSync(ast);
-
- visit(ast, "wikiLink", (node: Node) => {
- expect(node.data?.exists).toEqual(true);
- expect(node.data?.permalink).toEqual("/some/folder");
- expect(node.data?.alias).toEqual(null);
- expect(node.data?.hName).toEqual("a");
- expect((node.data?.hProperties as any).className).toEqual("internal");
- expect((node.data?.hProperties as any).href).toEqual("/some/folder");
- expect((node.data?.hChildren as any)[0].value).toEqual(
- "/some/folder/index"
- );
- });
- });
-
- test("parses a wiki link to home index page with no matching permalink", () => {
- const processor = unified().use(markdown).use(wikiLinkPlugin);
-
- let ast = processor.parse("[[/index]]");
- ast = processor.runSync(ast);
-
- visit(ast, "wikiLink", (node: Node) => {
- expect(node.data?.exists).toEqual(false);
- expect(node.data?.permalink).toEqual("/");
- expect(node.data?.alias).toEqual(null);
- expect(node.data?.hName).toEqual("a");
- expect((node.data?.hProperties as any).className).toEqual(
- "internal new"
- );
- expect((node.data?.hProperties as any).href).toEqual("/");
- expect((node.data?.hChildren as any)[0].value).toEqual("/index");
- });
- });
-
- test("parses a wiki link to home index page with a matching permalink", () => {
- const processor = unified()
- .use(markdown)
- .use(wikiLinkPlugin, { permalinks: ["/"] });
-
- let ast = processor.parse("[[/index]]");
- ast = processor.runSync(ast);
-
- visit(ast, "wikiLink", (node: Node) => {
- expect(node.data?.exists).toEqual(true);
- expect(node.data?.permalink).toEqual("/");
- expect(node.data?.alias).toEqual(null);
- expect(node.data?.hName).toEqual("a");
- expect((node.data?.hProperties as any).className).toEqual("internal");
- expect((node.data?.hProperties as any).href).toEqual("/");
- expect((node.data?.hChildren as any)[0].value).toEqual("/index");
- });
- });
- });
-
describe("transclusions", () => {
test("replaces a transclusion with a regular wiki link", () => {
const processor = unified().use(markdown).use(wikiLinkPlugin);
From a8fb176bcca0a01ed8c3c8c55661a8b4d9410f4b Mon Sep 17 00:00:00 2001
From: Ola Rubaj <52197250+olayway@users.noreply.github.com>
Date: Thu, 9 May 2024 02:12:44 +0200
Subject: [PATCH 3/5] rm test for custom permarlink converter (irrelevant)
---
.../test/getPermalinks.spec.ts | 31 -------------------
1 file changed, 31 deletions(-)
diff --git a/packages/remark-wiki-link/test/getPermalinks.spec.ts b/packages/remark-wiki-link/test/getPermalinks.spec.ts
index 6a34ad9c..ddd2e979 100644
--- a/packages/remark-wiki-link/test/getPermalinks.spec.ts
+++ b/packages/remark-wiki-link/test/getPermalinks.spec.ts
@@ -25,35 +25,4 @@ describe("getPermalinks", () => {
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);
- });
- });
});
From ce9ebbf41e640d6d760a321982b4ff2197ab90ca Mon Sep 17 00:00:00 2001
From: Ola Rubaj <52197250+olayway@users.noreply.github.com>
Date: Thu, 9 May 2024 02:16:05 +0200
Subject: [PATCH 4/5] add changeset file
---
.changeset/neat-bulldogs-exist.md | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 .changeset/neat-bulldogs-exist.md
diff --git a/.changeset/neat-bulldogs-exist.md b/.changeset/neat-bulldogs-exist.md
new file mode 100644
index 00000000..5cdd957a
--- /dev/null
+++ b/.changeset/neat-bulldogs-exist.md
@@ -0,0 +1,5 @@
+---
+'@portaljs/remark-wiki-link': minor
+---
+
+Treat "index" files as regular file names, i.e. do not remove it from the link. (Should be up to the client how to interpret URLs that end with "index").
From e4c456c237e8b1541fdf3bcbe651051845a4434e Mon Sep 17 00:00:00 2001
From: Ola Rubaj <52197250+olayway@users.noreply.github.com>
Date: Thu, 9 May 2024 02:19:54 +0200
Subject: [PATCH 5/5] rm changeset file
---
.changeset/neat-bulldogs-exist.md | 5 -----
1 file changed, 5 deletions(-)
delete mode 100644 .changeset/neat-bulldogs-exist.md
diff --git a/.changeset/neat-bulldogs-exist.md b/.changeset/neat-bulldogs-exist.md
deleted file mode 100644
index 5cdd957a..00000000
--- a/.changeset/neat-bulldogs-exist.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-'@portaljs/remark-wiki-link': minor
----
-
-Treat "index" files as regular file names, i.e. do not remove it from the link. (Should be up to the client how to interpret URLs that end with "index").