Skip to content

Commit ae6bfe6

Browse files
authored
repo sync
2 parents 1c6c0c8 + 8b86fd8 commit ae6bfe6

14 files changed

Lines changed: 115 additions & 193 deletions

File tree

contributing/content-markup-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
[Markdown](http://daringfireball.net/projects/markdown/) is a human-friendly syntax for formatting plain text. Our documentation is written with [GitHub Flavored Markdown](https://docs.github.com/en/github/writing-on-github/about-writing-and-formatting-on-github), a custom version of Markdown used across GitHub.
1818

19-
This site's Markdown rendering is powered by the [`/lib/render-content`](/lib/render-content) and [`hubdown`](https://github.com/electron/hubdown) npm packages, which are in turn built on the [`remark`](https://remark.js.org/) Markdown processor.
19+
This site's Markdown rendering is powered by [`/lib/render-content`](/lib/render-content), which is in turn built on the [`remark`](https://remark.js.org/) Markdown processor.
2020

2121
## Callout tags
2222

includes/scripts.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
<script id="search-options" type="application/json">{{ searchOptions }}</script>
12
<script src="{{ builtAssets.main.js }}"></script>

javascripts/copy-code.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import Clipboard from 'clipboard'
2-
31
export default () => {
4-
const clipboard = new Clipboard('button.js-btn-copy')
2+
const buttons = Array.from(document.querySelectorAll('button.js-btn-copy'))
3+
4+
if (!buttons) return
5+
6+
buttons.forEach(button =>
7+
button.addEventListener('click', async evt => {
8+
const text = button.dataset.clipboardText
9+
await navigator.clipboard.writeText(text)
510

6-
clipboard.on('success', evt => {
7-
const btn = evt.trigger
8-
const beforeTooltip = btn.getAttribute('aria-label')
9-
btn.setAttribute('aria-label', 'Copied!')
11+
const beforeTooltip = button.getAttribute('aria-label')
12+
button.setAttribute('aria-label', 'Copied!')
1013

11-
setTimeout(() => {
12-
btn.setAttribute('aria-label', beforeTooltip)
13-
}, 2000)
14-
})
14+
setTimeout(() => {
15+
button.setAttribute('aria-label', beforeTooltip)
16+
}, 2000)
17+
})
18+
)
1519
}

javascripts/display-platform-specific-content.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
const { getPlatformFromUserAgent } = require('platform-utils')
1+
import parseUserAgent from './user-agent'
22
const supportedPlatforms = ['mac', 'windows', 'linux']
33
const detectedPlatforms = new Set()
44

55
// Emphasize content for the visitor's OS (inferred from user agent string)
66

77
export default function displayPlatformSpecificContent () {
8-
let platform = getDefaultPlatform() || getPlatformFromUserAgent()
8+
let platform = getDefaultPlatform() || parseUserAgent().os
99

1010
// adjust platform names to fit existing mac/windows/linux scheme
1111
if (!platform) platform = 'mac' // default to 'mac' on mobile
1212
if (platform === 'darwin') platform = 'mac'
13+
if (platform === 'ios') platform = 'mac'
14+
if (platform === 'android') platform = 'linux'
1315
if (platform.startsWith('win')) platform = 'windows'
1416

1517
const platformsInContent = findPlatformSpecificContent(platform)

javascripts/search.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { tags } from './hyperscript'
22
import { sendEvent } from './events'
3-
const searchWithYourKeyboard = require('search-with-your-keyboard')
4-
const truncate = require('html-truncate')
5-
const languages = require('../lib/languages')
6-
const allVersions = require('../lib/all-versions')
7-
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
3+
import searchWithYourKeyboard from 'search-with-your-keyboard'
4+
import truncate from 'html-truncate'
85

9-
const languageCodes = Object.keys(languages)
106
const maxContentLength = 300
117

128
let $searchInputContainer
@@ -29,8 +25,13 @@ export default function search () {
2925
$searchOverlay = document.querySelector('.search-overlay-desktop')
3026

3127
// There's an index for every version/language combination
32-
version = deriveVersionFromPath()
33-
language = deriveLanguageCodeFromPath()
28+
const {
29+
languages,
30+
versions,
31+
nonEnterpriseDefaultVersion
32+
} = JSON.parse(document.getElementById('search-options').text)
33+
version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion)
34+
language = deriveLanguageCodeFromPath(languages)
3435

3536
// Find search placeholder text in a <meta> tag, falling back to a default
3637
const $placeholderMeta = document.querySelector('meta[name="site.data.ui.search.placeholder"]')
@@ -109,23 +110,16 @@ function closeSearch () {
109110
onSearch()
110111
}
111112

112-
function deriveLanguageCodeFromPath () {
113+
function deriveLanguageCodeFromPath (languageCodes) {
113114
let languageCode = location.pathname.split('/')[1]
114115
if (!languageCodes.includes(languageCode)) languageCode = 'en'
115116
return languageCode
116117
}
117118

118-
function deriveVersionFromPath () {
119+
function deriveVersionFromPath (allVersions, nonEnterpriseDefaultVersion) {
119120
// fall back to the non-enterprise default version (FPT currently) on the homepage, 404 page, etc.
120121
const versionStr = location.pathname.split('/')[2] || nonEnterpriseDefaultVersion
121-
const versionObject = allVersions[versionStr] || allVersions[nonEnterpriseDefaultVersion]
122-
123-
// if GHES, returns the release number like 2.21, 2.22, etc.
124-
// if FPT, returns 'dotcom'
125-
// if GHAE, returns 'ghae'
126-
return versionObject.plan === 'enterprise-server'
127-
? versionObject.currentRelease
128-
: versionObject.miscBaseName
122+
return allVersions[versionStr] || allVersions[nonEnterpriseDefaultVersion]
129123
}
130124

131125
// Wait for the event to stop triggering for X milliseconds before responding

javascripts/wrap-code-terms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import escape from 'lodash/escape'
12
const wordsLongerThan18Chars = /[\S]{18,}/g
23
const camelCaseChars = /([a-z])([A-Z])/g
34
const underscoresAfter12thChar = /([\w:]{12}[^_]*?)_/g
45
const slashChars = /([/\\])/g
5-
const { escape } = require('lodash')
66

77
// This module improves table rendering on reference pages by inserting a <wbr>
88
// tag in code terms that use camelcase, slashes, or underscores, inspired by
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const unified = require('unified')
2+
const markdown = require('remark-parse')
3+
const emoji = require('remark-gemoji-to-emoji')
4+
const remark2rehype = require('remark-rehype')
5+
const raw = require('rehype-raw')
6+
const slug = require('rehype-slug')
7+
const autolinkHeadings = require('rehype-autolink-headings')
8+
const highlight = require('rehype-highlight')
9+
const html = require('rehype-stringify')
10+
const graphql = require('highlightjs-graphql').definer
11+
const remarkCodeExtra = require('remark-code-extra')
12+
const codeHeader = require('./plugins/code-header')
13+
14+
module.exports = function createProcessor () {
15+
return unified()
16+
.use(markdown)
17+
.use(remarkCodeExtra, { transform: codeHeader })
18+
.use(emoji)
19+
.use(remark2rehype, { allowDangerousHTML: true })
20+
.use(slug)
21+
.use(autolinkHeadings, { behavior: 'wrap' })
22+
.use(highlight, { languages: { graphql }, subset: false })
23+
.use(raw)
24+
.use(html)
25+
}

lib/render-content/renderContent.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const liquid = require('./liquid')
2-
const codeHeader = require('./plugins/code-header')
3-
const hubdown = require('hubdown')
4-
const remarkCodeExtra = require('remark-code-extra')
52
const cheerio = require('cheerio')
63
const Entities = require('html-entities').XmlEntities
74
const entities = new Entities()
85
const stripHtmlComments = require('strip-html-comments')
6+
const createProcessor = require('./create-processor')
97

108
// used below to remove extra newlines in TOC lists
119
const endLine = '</a>\r?\n'
@@ -54,13 +52,9 @@ module.exports = async function renderContent (
5452
// statements so that extra space doesn't mess with list numbering
5553
template = template.replace(/(\r?\n){3}/g, '\n\n')
5654

57-
let { content: html } = await hubdown(template, {
58-
// Disable automatic language guessing in syntax highlighting
59-
highlight: { subset: false },
60-
runBefore: [[
61-
remarkCodeExtra, { transform: codeHeader }
62-
]]
63-
})
55+
const processor = createProcessor()
56+
const vFile = await processor.process(template)
57+
let html = vFile.toString()
6458

6559
// Remove unwanted newlines (which appear as spaces) from inline tags inside tables
6660
if (html.includes('<table>')) html = removeNewlinesFromInlineTags(html)

lib/search/versions.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const allVersions = require('../all-versions')
22

3-
module.exports = new Set(
4-
Object.values(allVersions)
5-
.map(version =>
3+
module.exports = Object.fromEntries(
4+
Object.entries(allVersions)
5+
.map(([versionStr, versionObject]) => [
6+
versionStr,
67
// if GHES, resolves to the release number like 2.21, 2.22, etc.
78
// if FPT, resolves to 'dotcom'
89
// if GHAE, resolves to 'ghae'
9-
version.plan === 'enterprise-server'
10-
? version.currentRelease
11-
: version.miscBaseName
12-
)
10+
versionObject.plan === 'enterprise-server'
11+
? versionObject.currentRelease
12+
: versionObject.miscBaseName
13+
])
1314
)

middleware/context.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const productNames = require('../lib/product-names')
88
const warmServer = require('../lib/warm-server')
99
const featureFlags = Object.keys(require('../feature-flags'))
1010
const builtAssets = require('../lib/built-asset-urls')
11+
const searchVersions = require('../lib/search/versions')
12+
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
1113

1214
// Supply all route handlers with a baseline `req.context` object
1315
// Note that additional middleware in middleware/index.js adds to this context object
@@ -46,5 +48,12 @@ module.exports = async function contextualize (req, res, next) {
4648
// JS + CSS asset paths
4749
req.context.builtAssets = builtAssets
4850

51+
// Languages and versions for search
52+
req.context.searchOptions = JSON.stringify({
53+
languages: Object.keys(languages),
54+
versions: searchVersions,
55+
nonEnterpriseDefaultVersion
56+
})
57+
4958
return next()
5059
}

0 commit comments

Comments
 (0)