From 53d8e60959cbb1a76f8309e7a89e919c64f41752 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Tue, 2 Feb 2021 13:14:39 -0500 Subject: [PATCH 1/2] Add a test for non-English rendering (#17593) * Throw in some code that should fail a test * Remove read-frontmatter behavior * Unskip the test that would catch this * Remove the throw to pass the test --- ...ion-tab.md => payment-information-tab.md} | 0 lib/page.js | 20 +------- lib/read-file-contents.js | 19 ++++++++ lib/read-frontmatter.js | 47 ------------------- tests/rendering/server.js | 3 +- 5 files changed, 23 insertions(+), 66 deletions(-) rename data/reusables/enterprise-accounts/{payment-information-tab.md => payment-information-tab.md} (100%) create mode 100644 lib/read-file-contents.js delete mode 100644 lib/read-frontmatter.js diff --git a/data/reusables/enterprise-accounts/payment-information-tab.md b/data/reusables/enterprise-accounts/payment-information-tab.md similarity index 100% rename from data/reusables/enterprise-accounts/payment-information-tab.md rename to data/reusables/enterprise-accounts/payment-information-tab.md diff --git a/lib/page.js b/lib/page.js index 22a9169494..3fa9430255 100644 --- a/lib/page.js +++ b/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) diff --git a/lib/read-file-contents.js b/lib/read-file-contents.js new file mode 100644 index 0000000000..4c80a4ab9f --- /dev/null +++ b/lib/read-file-contents.js @@ -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 }) +} diff --git a/lib/read-frontmatter.js b/lib/read-frontmatter.js deleted file mode 100644 index 3c3e529504..0000000000 --- a/lib/read-frontmatter.js +++ /dev/null @@ -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 }) -} diff --git a/tests/rendering/server.js b/tests/rendering/server.js index e7f4a1cdc9..bed0132490 100644 --- a/tests/rendering/server.js +++ b/tests/rendering/server.js @@ -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) From 04f074a913324e06f14e5504dabf767b24cf4de7 Mon Sep 17 00:00:00 2001 From: Shati Patel <42641846+shati-patel@users.noreply.github.com> Date: Tue, 2 Feb 2021 18:33:53 +0000 Subject: [PATCH 2/2] Add redirect for "About GitHub dependabot" --- .../about-dependabot-version-updates.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/github/administering-a-repository/about-dependabot-version-updates.md b/content/github/administering-a-repository/about-dependabot-version-updates.md index 2d22d16021..1ade8a1acb 100644 --- a/content/github/administering-a-repository/about-dependabot-version-updates.md +++ b/content/github/administering-a-repository/about-dependabot-version-updates.md @@ -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: