Skip to content

Commit

Permalink
fix: add an option to disable new tabs in modern template
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih committed May 4, 2023
1 parent e2c800a commit 8585def
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Name | Type | Description
`_appLogoPath` | string | App logo URL path.
`_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 _"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.
`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`.
Expand Down
1 change: 1 addition & 0 deletions samples/seed/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: landing
lang: zh-CN
_disableNewTab: true
---

# docfx-seed
Expand Down
1 change: 1 addition & 0 deletions templates/modern/layout/_master.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<meta name="docfx:tocrel" content="{{_tocRel}}">
{{#_noindex}}<meta name="searchOption" content="noindex">{{/_noindex}}
{{#_enableSearch}}<meta name="docfx:rel" content="{{_rel}}">{{/_enableSearch}}
{{#_disableNewTab}}<meta name="docfx:disablenewtab" content="true">{{/_disableNewTab}}
{{#docurl}}<meta name="docfx:docurl" content="{{docurl}}">{{/docurl}}

<script type="module">
Expand Down
6 changes: 5 additions & 1 deletion templates/modern/src/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import { breakWord } from './helper'
import { breakWord, meta } from './helper'
import AnchorJs from 'anchor-js'
import { html, render } from 'lit-html'
import mermaid from 'mermaid'
Expand Down Expand Up @@ -118,6 +118,10 @@ function renderAlerts() {
* Open external links to different host in a new window.
*/
function renderLinks() {
if (meta('docfx:disablenewtab') === 'true') {
return
}

document.querySelectorAll<HTMLAnchorElement>('article a[href]').forEach(a => {
if (a.hostname !== window.location.hostname && a.innerText.trim() !== '') {
a.target = '_blank'
Expand Down

0 comments on commit 8585def

Please sign in to comment.