-
Notifications
You must be signed in to change notification settings - Fork 153
normalize links #1037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
normalize links #1037
Conversation
|
src/markdown.ts
Outdated
export function mdparser({markdownIt}: {markdownIt?: (md: MarkdownIt) => MarkdownIt} = {}): MarkdownIt { | ||
function cleanPath(href: string, clean: boolean): string { | ||
if (href.startsWith("./") || href.startsWith("../")) { | ||
const g = href.match(/(?<dir>[^#?]*\/)((?<file>[^/?#]*?)([.]html)?)(?<q>[?#].*)?$/)?.groups; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use URL
to parse, and dirname
, basename
, extname
? Regular expressions…
src/preview.ts
Outdated
return; | ||
path = path.slice(0, -".html".length); | ||
pathname = pathname.slice(0, -".html".length); | ||
if (config.md.normalizeLink("./hello") === "./hello") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little icky. Wouldn’t it be better to check the value of config.md.normalizeLink(path)
instead, and then redirect to the normalized value? Otherwise we’re essentially duplicating the logic of normalizeLink
and assuming its behavior. Or if we want to assume its behavior, then we should expose config.cleanUrls
instead of trying to invert it by calling md.normalizeLink
.
src/search.ts
Outdated
@@ -81,7 +81,8 @@ export async function searchIndex(config: Config, effects = defaultEffects): Pro | |||
options: { | |||
fields: indexOptions.fields, | |||
storeFields: indexOptions.storeFields | |||
} | |||
}, | |||
cleanUrls: config.md.normalizeLink("./hello") === "./hello" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above. If we expect md.normalizeLink
to be overridden and have some other behavior, then we need to pass the normalized links to minisearch so that it renders normalized links on the client. On the other hand, if we only want to support our more limited definition of cleanUrls
, then we shouldn’t test the behavior of md.normalizeLink
; we should explicitly track the setting in the config.
I guess it’d be cool to respect the implementation of md.normalizeLink
, if it’s not too much work. Perhaps we could invoke it up above when computing the id
rather than having the client do the normalization and repeating the logic?
I moved all the normalization to the server-side and got rid of the |
This introduces a cleanUrls option (boolean, defaults to true) that indicates whether links to pages should end with ".html" (except for directories, where the convention is that the file
dir/index.html
is served with thedir/
path).This option is subsumed in the definition of
config.md.normalizeLinks
, which is applied to all links generated by Markdown text and now also by links generated in the sidebar, in the pager, and in the search results. (It is not applied to links that are written directly in HTML.)closes #92
based on #1034
This could also help re-implement a normalization of the pager (#689 #1022)