Branch was updated using the 'autoupdate branch' Actions workflow.
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import { tags } from './hyperscript'
|
||||
import { sendEvent } from './events'
|
||||
import searchWithYourKeyboard from 'search-with-your-keyboard'
|
||||
import truncate from 'html-truncate'
|
||||
|
||||
const maxContentLength = 300
|
||||
|
||||
let $searchInputContainer
|
||||
let $searchResultsContainer
|
||||
@@ -274,8 +271,7 @@ function tmplSearchResult ({ url, breadcrumbs, heading, title, content }) {
|
||||
),
|
||||
div(
|
||||
{ class: 'search-result-content d-block text-gray' },
|
||||
// Truncate without breaking inner HTML tags
|
||||
markify(truncate(content, maxContentLength))
|
||||
markify(content)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
20
lib/page.js
20
lib/page.js
@@ -1,11 +1,9 @@
|
||||
const assert = require('assert')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const cheerio = require('cheerio')
|
||||
const patterns = require('./patterns')
|
||||
const getMapTopicContent = require('./get-map-topic-content')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const encodeBracketedParentheses = require('./encode-bracketed-parentheses')
|
||||
const generateRedirectsForPermalinks = require('./redirects/permalinks')
|
||||
const getEnglishHeadings = require('./get-english-headings')
|
||||
const getTocItems = require('./get-toc-items')
|
||||
@@ -14,11 +12,10 @@ const Permalink = require('./permalink')
|
||||
const languages = require('./languages')
|
||||
const renderContent = require('./render-content')
|
||||
const { renderReact } = require('./react/engine')
|
||||
const frontmatter = require('./frontmatter')
|
||||
const products = require('./all-products')
|
||||
const slash = require('slash')
|
||||
const statsd = require('./statsd')
|
||||
const fmfromf = require('./read-frontmatter')
|
||||
const readFileContents = require('./read-file-contents')
|
||||
const getLinkData = require('./get-link-data')
|
||||
const union = require('lodash/union')
|
||||
|
||||
@@ -40,7 +37,7 @@ class Page {
|
||||
// Per https://nodejs.org/api/fs.html#fs_fs_exists_path_callback
|
||||
// its better to read and handle errors than to check access/stats first
|
||||
try {
|
||||
const { data, content, errors: frontmatterErrors } = await fmfromf(fullPath, opts.languageCode)
|
||||
const { data, content, errors: frontmatterErrors } = await readFileContents(fullPath, opts.languageCode)
|
||||
|
||||
return {
|
||||
...opts,
|
||||
@@ -138,20 +135,7 @@ class Page {
|
||||
: this.renderProp('title', context, opts)
|
||||
}
|
||||
|
||||
async getMarkdown () {
|
||||
const raw = fs.readFileSync(this.fullPath, 'utf8')
|
||||
const { content } = frontmatter(raw, { filepath: this.fullPath })
|
||||
// prevent `[foo] (bar)` strings with a space between from being interpreted as markdown links
|
||||
const encodedMarkdown = encodeBracketedParentheses(content)
|
||||
return encodedMarkdown
|
||||
}
|
||||
|
||||
async _render (context) {
|
||||
// Get the raw markdown if we need to
|
||||
if (!this.markdown) {
|
||||
this.markdown = await this.getMarkdown()
|
||||
}
|
||||
|
||||
// use English IDs/anchors for translated headings, so links don't break (see #8572)
|
||||
if (this.languageCode !== 'en') {
|
||||
const englishHeadings = getEnglishHeadings(this, context.pages)
|
||||
|
||||
19
lib/read-file-contents.js
Normal file
19
lib/read-file-contents.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const fs = require('fs')
|
||||
const encodeBracketedParentheses = require('./encode-bracketed-parentheses')
|
||||
const fm = require('./frontmatter')
|
||||
|
||||
/**
|
||||
* Read only the frontmatter from file
|
||||
*/
|
||||
module.exports = async function fmfromf (filepath, languageCode) {
|
||||
let fileContent = await fs.promises.readFile(filepath, 'utf8')
|
||||
|
||||
fileContent = encodeBracketedParentheses(fileContent)
|
||||
|
||||
// TODO remove this when crowdin-support issue 66 has been resolved
|
||||
if (languageCode !== 'en' && fileContent.includes(': verdadero')) {
|
||||
fileContent = fileContent.replace(': verdadero', ': true')
|
||||
}
|
||||
|
||||
return fm(fileContent, { filepath })
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const fm = require('./frontmatter')
|
||||
|
||||
const endLine = '\n---\n'
|
||||
|
||||
/**
|
||||
* Reads the given filepath, but only up until `endLine`, using streams to
|
||||
* read each chunk and close the stream early.
|
||||
*/
|
||||
async function readFrontmatter (filepath) {
|
||||
const readStream = fs.createReadStream(filepath, { encoding: 'utf8', emitClose: true })
|
||||
return new Promise((resolve, reject) => {
|
||||
let frontmatter = ''
|
||||
readStream
|
||||
.on('data', function (chunk) {
|
||||
const endOfFrontmatterIndex = chunk.indexOf(endLine)
|
||||
if (endOfFrontmatterIndex !== -1) {
|
||||
frontmatter += chunk.slice(0, endOfFrontmatterIndex + endLine.length)
|
||||
// Stop early!
|
||||
readStream.destroy()
|
||||
} else {
|
||||
frontmatter += chunk
|
||||
}
|
||||
})
|
||||
.on('error', (error) => reject(error))
|
||||
// Stream has been destroyed and file has been closed
|
||||
.on('close', () => resolve(frontmatter))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Read only the frontmatter from a file
|
||||
*/
|
||||
module.exports = async function fmfromf (filepath, languageCode) {
|
||||
let fileContent = filepath.endsWith('index.md')
|
||||
// For index files, we need to read the whole file because they contain ToC info
|
||||
? await fs.promises.readFile(filepath, 'utf8')
|
||||
// For everything else, only read the frontmatter
|
||||
: await readFrontmatter(filepath)
|
||||
|
||||
// TODO remove this when crowdin-support issue 66 has been resolved
|
||||
if (languageCode !== 'en' && fileContent.includes(': verdadero')) {
|
||||
fileContent = fileContent.replace(': verdadero', ': true')
|
||||
}
|
||||
|
||||
return fm(fileContent, { filepath })
|
||||
}
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -12784,11 +12784,6 @@
|
||||
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
|
||||
"dev": true
|
||||
},
|
||||
"html-truncate": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/html-truncate/-/html-truncate-1.2.2.tgz",
|
||||
"integrity": "sha1-2y4zHc8cugvUMqUH0W6YhgnyV18="
|
||||
},
|
||||
"html-void-elements": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-1.0.5.tgz",
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
"highlightjs-graphql": "^1.0.2",
|
||||
"hot-shots": "^8.2.0",
|
||||
"html-entities": "^1.2.1",
|
||||
"html-truncate": "^1.2.2",
|
||||
"imurmurhash": "^0.1.4",
|
||||
"ioredis": "^4.19.4",
|
||||
"ioredis-mock": "^5.2.0",
|
||||
|
||||
@@ -42,7 +42,6 @@ const main = async () => {
|
||||
'style-loader',
|
||||
'webpack-cli',
|
||||
'browser-date-formatter',
|
||||
'html-truncate',
|
||||
'search-with-your-keyboard',
|
||||
'uuid',
|
||||
'imurmurhash',
|
||||
|
||||
@@ -89,6 +89,11 @@ mark,
|
||||
}
|
||||
}
|
||||
|
||||
.search-result-content {
|
||||
max-height: 4rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.search-result-title em {
|
||||
font-style: normal;
|
||||
text-decoration: underline;
|
||||
|
||||
@@ -483,8 +483,9 @@ describe('server', () => {
|
||||
|
||||
describe('URLs by language', () => {
|
||||
// TODO re-enable this test once TOCs are auto-generated (after PR 11731 has landed)
|
||||
test.skip('heading IDs and links on translated pages are in English', async () => {
|
||||
test('heading IDs and links on translated pages are in English', async () => {
|
||||
const $ = await getDOM('/ja/github/getting-started-with-github/verifying-your-email-address')
|
||||
expect($.res.statusCode).toBe(200)
|
||||
expect($('h3[id="further-reading"]').length).toBe(1)
|
||||
expect($('h3[id="参考リンク"]').length).toBe(0)
|
||||
expect($('h3 a[href="#further-reading"]').length).toBe(1)
|
||||
|
||||
Reference in New Issue
Block a user