1
0
mirror of synced 2026-01-04 00:06:20 -05:00

repo sync

This commit is contained in:
Octomerger Bot
2021-02-03 05:01:35 +10:00
committed by GitHub
6 changed files with 24 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ title: About Dependabot version updates
intro: 'You can use {% data variables.product.prodname_dependabot %} to keep the packages you use updated to the latest versions.'
redirect_from:
- /github/administering-a-repository/about-dependabot
- /github/administering-a-repository/about-github-dependabot
- /github/administering-a-repository/about-github-dependabot-version-updates
versions:

View File

@@ -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
View 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 })
}

View File

@@ -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 })
}

View File

@@ -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)