Skip to content

Commit

Permalink
Link resolution is more predictable and less overall stupid (#47)
Browse files Browse the repository at this point in the history
* Link resolution is more predictable and less overall stupid

* Update typedoc link mapping

* Go back to resolving hashed mapped links correctly

* Fixes for mapped links
  • Loading branch information
irskep authored Sep 5, 2024
1 parent 8e5972f commit 611b3af
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 154 deletions.
2 changes: 1 addition & 1 deletion docs/out/gfm/features/typedoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Djockey can integrate with [TypeDoc](https://typedoc.org) to create an
integrated documentation experience that combines the authoring power of
Djockey with rich API references. For example, here in the Djockey docs,
we can type `[](:ts:DjockeyPlugin)` and get
[DjockeyPlugin](../api//interfaces/DjockeyPlugin.html).
[DjockeyPlugin](../api/interfaces/DjockeyPlugin.html).

The core concept is to render TypeDoc normally inside your docs
directory, treat its output as static files, and then create convenient
Expand Down
87 changes: 71 additions & 16 deletions docs/out/gfm/typescript_link_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
"relativeURL": "classes/LogCollector.html#label",
"defaultLabel": "label"
},
{
"linkDestination": "LogCollector.hasWarningsOrErrors",
"relativeURL": "classes/LogCollector.html#hasWarningsOrErrors",
"defaultLabel": "hasWarningsOrErrors"
},
{
"linkDestination": "hasWarningsOrErrors",
"relativeURL": "classes/LogCollector.html#hasWarningsOrErrors",
"defaultLabel": "hasWarningsOrErrors"
},
{
"linkDestination": "LogCollector.debug",
"relativeURL": "classes/LogCollector.html#debug",
Expand Down Expand Up @@ -146,6 +156,16 @@
"relativeURL": "classes/LogCollector.html#fail",
"defaultLabel": "fail"
},
{
"linkDestination": "LogCollector.getChild",
"relativeURL": "classes/LogCollector.html#getChild",
"defaultLabel": "getChild"
},
{
"linkDestination": "getChild",
"relativeURL": "classes/LogCollector.html#getChild",
"defaultLabel": "getChild"
},
{
"linkDestination": "LogCollector.info",
"relativeURL": "classes/LogCollector.html#info",
Expand Down Expand Up @@ -431,16 +451,6 @@
"relativeURL": "interfaces/DjockeyDoc.html",
"defaultLabel": "DjockeyDoc"
},
{
"linkDestination": "DjockeyDoc.absolutePath",
"relativeURL": "interfaces/DjockeyDoc.html#absolutePath",
"defaultLabel": "absolutePath"
},
{
"linkDestination": "absolutePath",
"relativeURL": "interfaces/DjockeyDoc.html#absolutePath",
"defaultLabel": "absolutePath"
},
{
"linkDestination": "DjockeyDoc.data",
"relativeURL": "interfaces/DjockeyDoc.html#data",
Expand Down Expand Up @@ -481,6 +491,16 @@
"relativeURL": "interfaces/DjockeyDoc.html#frontMatter",
"defaultLabel": "frontMatter"
},
{
"linkDestination": "DjockeyDoc.fsPath",
"relativeURL": "interfaces/DjockeyDoc.html#fsPath",
"defaultLabel": "fsPath"
},
{
"linkDestination": "fsPath",
"relativeURL": "interfaces/DjockeyDoc.html#fsPath",
"defaultLabel": "fsPath"
},
{
"linkDestination": "DjockeyDoc.neighbors",
"relativeURL": "interfaces/DjockeyDoc.html#neighbors",
Expand All @@ -502,14 +522,14 @@
"defaultLabel": "originalExtension"
},
{
"linkDestination": "DjockeyDoc.relativePath",
"relativeURL": "interfaces/DjockeyDoc.html#relativePath",
"defaultLabel": "relativePath"
"linkDestination": "DjockeyDoc.refPath",
"relativeURL": "interfaces/DjockeyDoc.html#refPath",
"defaultLabel": "refPath"
},
{
"linkDestination": "relativePath",
"relativeURL": "interfaces/DjockeyDoc.html#relativePath",
"defaultLabel": "relativePath"
"linkDestination": "refPath",
"relativeURL": "interfaces/DjockeyDoc.html#refPath",
"defaultLabel": "refPath"
},
{
"linkDestination": "DjockeyDoc.title",
Expand Down Expand Up @@ -626,6 +646,16 @@
"relativeURL": "interfaces/DjockeyPlugin.html#getNodeReservations",
"defaultLabel": "getNodeReservations"
},
{
"linkDestination": "DjockeyPlugin.getStaticFiles",
"relativeURL": "interfaces/DjockeyPlugin.html#getStaticFiles",
"defaultLabel": "getStaticFiles"
},
{
"linkDestination": "getStaticFiles",
"relativeURL": "interfaces/DjockeyPlugin.html#getStaticFiles",
"defaultLabel": "getStaticFiles"
},
{
"linkDestination": "DjockeyPlugin.name",
"relativeURL": "interfaces/DjockeyPlugin.html#name",
Expand Down Expand Up @@ -706,6 +736,31 @@
"relativeURL": "interfaces/DjockeyPluginNodeReservation.html#match",
"defaultLabel": "match"
},
{
"linkDestination": "DjockeyStaticFileFromPlugin",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html",
"defaultLabel": "DjockeyStaticFileFromPlugin"
},
{
"linkDestination": "DjockeyStaticFileFromPlugin.contents",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#contents",
"defaultLabel": "contents"
},
{
"linkDestination": "contents",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#contents",
"defaultLabel": "contents"
},
{
"linkDestination": "DjockeyStaticFileFromPlugin.path",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#path",
"defaultLabel": "path"
},
{
"linkDestination": "path",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#path",
"defaultLabel": "path"
},
{
"linkDestination": "LinkMappingConfig",
"relativeURL": "interfaces/LinkMappingConfig.html",
Expand Down
87 changes: 71 additions & 16 deletions docs/src/typescript_link_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
"relativeURL": "classes/LogCollector.html#label",
"defaultLabel": "label"
},
{
"linkDestination": "LogCollector.hasWarningsOrErrors",
"relativeURL": "classes/LogCollector.html#hasWarningsOrErrors",
"defaultLabel": "hasWarningsOrErrors"
},
{
"linkDestination": "hasWarningsOrErrors",
"relativeURL": "classes/LogCollector.html#hasWarningsOrErrors",
"defaultLabel": "hasWarningsOrErrors"
},
{
"linkDestination": "LogCollector.debug",
"relativeURL": "classes/LogCollector.html#debug",
Expand Down Expand Up @@ -146,6 +156,16 @@
"relativeURL": "classes/LogCollector.html#fail",
"defaultLabel": "fail"
},
{
"linkDestination": "LogCollector.getChild",
"relativeURL": "classes/LogCollector.html#getChild",
"defaultLabel": "getChild"
},
{
"linkDestination": "getChild",
"relativeURL": "classes/LogCollector.html#getChild",
"defaultLabel": "getChild"
},
{
"linkDestination": "LogCollector.info",
"relativeURL": "classes/LogCollector.html#info",
Expand Down Expand Up @@ -431,16 +451,6 @@
"relativeURL": "interfaces/DjockeyDoc.html",
"defaultLabel": "DjockeyDoc"
},
{
"linkDestination": "DjockeyDoc.absolutePath",
"relativeURL": "interfaces/DjockeyDoc.html#absolutePath",
"defaultLabel": "absolutePath"
},
{
"linkDestination": "absolutePath",
"relativeURL": "interfaces/DjockeyDoc.html#absolutePath",
"defaultLabel": "absolutePath"
},
{
"linkDestination": "DjockeyDoc.data",
"relativeURL": "interfaces/DjockeyDoc.html#data",
Expand Down Expand Up @@ -481,6 +491,16 @@
"relativeURL": "interfaces/DjockeyDoc.html#frontMatter",
"defaultLabel": "frontMatter"
},
{
"linkDestination": "DjockeyDoc.fsPath",
"relativeURL": "interfaces/DjockeyDoc.html#fsPath",
"defaultLabel": "fsPath"
},
{
"linkDestination": "fsPath",
"relativeURL": "interfaces/DjockeyDoc.html#fsPath",
"defaultLabel": "fsPath"
},
{
"linkDestination": "DjockeyDoc.neighbors",
"relativeURL": "interfaces/DjockeyDoc.html#neighbors",
Expand All @@ -502,14 +522,14 @@
"defaultLabel": "originalExtension"
},
{
"linkDestination": "DjockeyDoc.relativePath",
"relativeURL": "interfaces/DjockeyDoc.html#relativePath",
"defaultLabel": "relativePath"
"linkDestination": "DjockeyDoc.refPath",
"relativeURL": "interfaces/DjockeyDoc.html#refPath",
"defaultLabel": "refPath"
},
{
"linkDestination": "relativePath",
"relativeURL": "interfaces/DjockeyDoc.html#relativePath",
"defaultLabel": "relativePath"
"linkDestination": "refPath",
"relativeURL": "interfaces/DjockeyDoc.html#refPath",
"defaultLabel": "refPath"
},
{
"linkDestination": "DjockeyDoc.title",
Expand Down Expand Up @@ -626,6 +646,16 @@
"relativeURL": "interfaces/DjockeyPlugin.html#getNodeReservations",
"defaultLabel": "getNodeReservations"
},
{
"linkDestination": "DjockeyPlugin.getStaticFiles",
"relativeURL": "interfaces/DjockeyPlugin.html#getStaticFiles",
"defaultLabel": "getStaticFiles"
},
{
"linkDestination": "getStaticFiles",
"relativeURL": "interfaces/DjockeyPlugin.html#getStaticFiles",
"defaultLabel": "getStaticFiles"
},
{
"linkDestination": "DjockeyPlugin.name",
"relativeURL": "interfaces/DjockeyPlugin.html#name",
Expand Down Expand Up @@ -706,6 +736,31 @@
"relativeURL": "interfaces/DjockeyPluginNodeReservation.html#match",
"defaultLabel": "match"
},
{
"linkDestination": "DjockeyStaticFileFromPlugin",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html",
"defaultLabel": "DjockeyStaticFileFromPlugin"
},
{
"linkDestination": "DjockeyStaticFileFromPlugin.contents",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#contents",
"defaultLabel": "contents"
},
{
"linkDestination": "contents",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#contents",
"defaultLabel": "contents"
},
{
"linkDestination": "DjockeyStaticFileFromPlugin.path",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#path",
"defaultLabel": "path"
},
{
"linkDestination": "path",
"relativeURL": "interfaces/DjockeyStaticFileFromPlugin.html#path",
"defaultLabel": "path"
},
{
"linkDestination": "LinkMappingConfig",
"relativeURL": "interfaces/LinkMappingConfig.html",
Expand Down
48 changes: 44 additions & 4 deletions src/plugins/linkRewritingPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
import { resolveRelativePath } from "./linkRewritingPlugin.js";
import { Doc } from "@djot/djot";
import {
MappableLinkTarget,
resolveRelativeRefPath,
} from "./linkRewritingPlugin.js";

test("Resolves explicit relative links", () => {
expect(resolveRelativePath("a/b/c.txt", "./d.txt")).toEqual("/a/b/d.txt");
expect(resolveRelativePath("a/b/c.txt", "./../d.txt")).toEqual("/a/d.txt");
expect(resolveRelativePath("a/b/c.txt", "../d.txt")).toEqual("/a/d.txt");
expect(resolveRelativeRefPath("a/b/c.txt", "./d.txt")).toEqual("/a/b/d.txt");
expect(resolveRelativeRefPath("a/b/c.txt", "./../d.txt")).toEqual("/a/d.txt");
expect(resolveRelativeRefPath("a/b/c.txt", "../d.txt")).toEqual("/a/d.txt");
});

test("MappableLinkTarget has expected values", () => {
const stubDoc: Doc = {
tag: "doc",
references: {},
autoReferences: {},
footnotes: {},
children: [],
};
const t = new MappableLinkTarget(
{
docs: {
content: stubDoc,
},
title: "The Doc",
titleAST: [],
originalExtension: ".djot",
fsPath: "/fsroot/input/subdir/the_doc.djot",
refPath: "subdir/the_doc",
filename: "the_doc",
frontMatter: {},
data: {},
},
"the-hash"
);

expect(t.aliases).toEqual([
"#the-hash",
"the_doc#the-hash",
"the_doc.djot#the-hash",
"subdir/the_doc#the-hash",
"subdir/the_doc.djot#the-hash",
"/subdir/the_doc#the-hash",
"/subdir/the_doc.djot#the-hash",
]);
});
Loading

0 comments on commit 611b3af

Please sign in to comment.