Skip to content
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

feat(modern-template): respect url normalization for toc #9036

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions docs/docs/template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Template

Template defines the appearance of the website.
Template defines the appearance of the website.

Docfx ships several built-in templates. We recommend using the modern template that matches the look and feel of this site. It supports dark mode, more features, rich customization options and.

Expand All @@ -26,30 +26,31 @@ The easiest way of customizing the the appearance of pages is using [metadata](.

# [Modern Template](#tab/modern)

Name | Type | Description
----------------------|---------|---------------------------
`_appTitle` | string | A string append to every page title.
`_appName` | string | The name of the site displayed after logo.
`_appFooter` | string | The footer HTML.
`_appLogoPath` | string | Path to the app logo.
`_appLogoUrl` | string | URL for the app logo.
`_appFaviconPath` | string | Favicon URL path.
`_enableSearch` | bool | Whether to show the search box.
`_noindex` | bool | Whether to include in search results
`_disableContribution` | bool | Whether to show the _"Edit this page"_ button.
`_gitContribute` | object | Defines the `repo` and `branch` property of git links.
`_gitUrlPattern` | string | URL pattern of git links.
`_disableNewTab` | bool | Whether to render external link indicator icons and open external links in a new tab.
`_disableNextArticle` | bool | Whether to show the previous and next article link.
`_disableTocFilter` | bool | Whether to show the table of content filter box.
`_googleAnalyticsTagId` | string | Enables Google Analytics web traffic analysis.
`_lang` | string | Primary language of the page. If unset, the `<html>` tag will not have `lang` property.
`_layout` | string | Determines the layout of the page. Supported values are `landing` and `chromeless`.
Name | Type | Description
--------------------------|---------|---------------------------
`_appTitle` | string | A string append to every page title.
`_appName` | string | The name of the site displayed after logo.
`_appFooter` | string | The footer HTML.
`_appLogoPath` | string | Path to the app logo.
`_appLogoUrl` | string | URL for the app logo.
`_appFaviconPath` | string | Favicon URL path.
`_enableSearch` | bool | Whether to show the search box.
`_noindex` | bool | Whether to include in search results
`_disableContribution` | bool | Whether to show the _"Edit this page"_ button.
`_gitContribute` | object | Defines the `repo` and `branch` property of git links.
`_gitUrlPattern` | string | URL pattern of git links.
`_disableNewTab` | bool | Whether to render external link indicator icons and open external links in a new tab.
`_disableNextArticle` | bool | Whether to show the previous and next article link.
`_disableTocFilter` | bool | Whether to show the table of content filter box.
`_googleAnalyticsTagId` | string | Enables Google Analytics web traffic analysis.
`_lang` | string | Primary language of the page. If unset, the `<html>` tag will not have `lang` property.
`_layout` | string | Determines the layout of the page. Supported values are `landing` and `chromeless`.
`_urlNormalizationActive` | bool | Whether any url normalization rules are active. If unset, the default value is `false`.

# [Default Template](#tab/default)

Name | Type | Description
----------------------|---------|---------------------------
Name | Type | Description
------------------------|---------|---------------------------
`_appTitle` | string | A string append to every page title.
`_appName` | string | The name of the site displayed after logo.
`_appFooter` | string | The footer HTML.
Expand All @@ -58,7 +59,7 @@ Name | Type | Description
`_appFaviconPath` | string | Favicon URL path.
`_enableSearch` | bool | Whether to show the search box.
`_enableNewTab` | bool | Whether to open external links in a new tab.
`_noindex` | bool | Whether to include in search results
`_noindex` | bool | Whether to include in search results
`_disableContribution` | bool | Whether to show the _"Improve this Doc"_ and _"View Source"_ buttons.
`_gitContribute` | object | Defines the `repo` and `branch` property of git links.
`_gitUrlPattern` | string | URL pattern of git links.
Expand All @@ -67,7 +68,7 @@ Name | Type | Description
`_disableToc` | bool | Whether to show the TOC.
`_disableAffix` | bool | Whether to show the right rail.
`_googleAnalyticsTagId` | string | Enables Google Analytics web traffic analysis.
`_lang` | string | Primary language of the page. If unset, the `<html>` tag will not have `lang` property.
`_lang` | string | Primary language of the page. If unset, the `<html>` tag will not have `lang` property.

---

Expand Down
5 changes: 3 additions & 2 deletions templates/modern/layout/_master.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{{#_enableSearch}}<meta name="docfx:rel" content="{{_rel}}">{{/_enableSearch}}
{{#_disableNewTab}}<meta name="docfx:disablenewtab" content="true">{{/_disableNewTab}}
{{#_disableTocFilter}}<meta name="docfx:disabletocfilter" content="true">{{/_disableTocFilter}}
{{#_urlNormalizationActive}}<meta name="docfx:urlnormalizationactive" content="true">{{/_urlNormalizationActive}}
{{#docurl}}<meta name="docfx:docurl" content="{{docurl}}">{{/docurl}}
{{/redirect_url}}
</head>
Expand Down Expand Up @@ -117,7 +118,7 @@
{{^_disableNextArticle}}
<div class="next-article d-print-none border-top" id="nextArticle"></div>
{{/_disableNextArticle}}

</div>

<div class="affix">
Expand All @@ -138,4 +139,4 @@
</footer>
</body>
{{/redirect_url}}
</html>
</html>
8 changes: 7 additions & 1 deletion templates/modern/src/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ export async function renderToc(): Promise<TocNode[]> {
}

function normalizeUrlPath(url: { pathname: string }): string {
return url.pathname.replace(/\/index\.html$/gi, '/')
const urlNormalization = meta('docfx:urlnormalizationactive')

if (urlNormalization !== undefined && urlNormalization !== null && urlNormalization === 'true' && !url.pathname.endsWith('/index.html') && !url.pathname.endsWith('.html') && !url.pathname.endsWith('/')) {
return url.pathname + '.html'
} else {
return url.pathname.replace(/\/index\.html$/gi, '/')
}
}
}

Expand Down