Skip to content

Commit 9b66f33

Browse files
authored
repo sync
2 parents a52d563 + 0ac79f6 commit 9b66f33

10 files changed

Lines changed: 103 additions & 142 deletions

File tree

lib/page.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const assert = require('assert')
2-
const fs = require('fs').promises
2+
const fs = require('fs')
33
const path = require('path')
44
const cheerio = require('cheerio')
55
const patterns = require('./patterns')
@@ -23,30 +23,15 @@ const slash = require('slash')
2323
const statsd = require('./statsd')
2424

2525
class Page {
26-
static async init (opts) {
26+
constructor (opts) {
2727
assert(opts.relativePath, 'relativePath is required')
2828
assert(opts.basePath, 'basePath is required')
29-
30-
const relativePath = slash(opts.relativePath)
31-
const fullPath = slash(path.join(opts.basePath, relativePath))
32-
const raw = await fs.readFile(fullPath, 'utf8')
33-
34-
return new Page({ ...opts, relativePath, fullPath, raw })
35-
}
36-
37-
static async exists (path) {
38-
try {
39-
return await fs.stat(path)
40-
} catch (err) {
41-
if (err.code === 'ENOENT') return false
42-
console.error(err)
43-
}
44-
}
45-
46-
constructor (opts) {
4729
assert(opts.languageCode, 'languageCode is required')
4830

4931
Object.assign(this, { ...opts })
32+
this.relativePath = slash(this.relativePath)
33+
this.fullPath = slash(path.join(this.basePath, this.relativePath))
34+
this.raw = fs.readFileSync(this.fullPath, 'utf8')
5035

5136
// TODO remove this when crowdin-support issue 66 has been resolved
5237
if (this.languageCode !== 'en' && this.raw.includes(': verdadero')) {

lib/pages.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,42 @@ const path = require('path')
22
const walk = require('walk-sync').entries
33
const Page = require('./page')
44
const languages = require('./languages')
5-
const { mapLimit, filterLimit } = require('async')
6-
const FILE_READ_LIMIT = 500
5+
const fs = require('fs')
76

87
async function loadPageList () {
98
const pageList = []
109

1110
// load english pages
1211
const englishPath = path.join(__dirname, '..', languages.en.dir, 'content')
13-
const englishPaths = walk(englishPath)
14-
.filter(({ relativePath }) =>
15-
relativePath.endsWith('.md') && !relativePath.includes('README')
16-
)
17-
const englishPages = await mapLimit(
18-
englishPaths,
19-
FILE_READ_LIMIT,
20-
async fileData => await Page.init({ ...fileData, languageCode: languages.en.code })
21-
)
12+
const englishPages = walk(englishPath)
13+
.filter(({ relativePath }) => {
14+
return relativePath.endsWith('.md') &&
15+
!relativePath.includes('README')
16+
})
17+
.map(fileData => new Page({ ...fileData, languageCode: languages.en.code }))
18+
2219
pageList.push(...englishPages)
2320

2421
// load matching pages in other languages
25-
let localizedPaths = Object.values(languages)
26-
.filter(({ code }) => code !== 'en')
27-
.map(language => {
22+
for (const page of englishPages) {
23+
for (const language of Object.values(languages)) {
24+
if (language.code === 'en') continue
25+
2826
const basePath = path.join(__dirname, '..', language.dir, 'content')
29-
return englishPages.map(page => ({
30-
basePath,
27+
const localizedPath = path.join(basePath, page.relativePath)
28+
try {
29+
fs.statSync(localizedPath)
30+
} catch (_) {
31+
continue
32+
}
33+
34+
pageList.push(new Page({
3135
relativePath: page.relativePath,
32-
localizedPath: path.join(basePath, page.relativePath),
36+
basePath,
3337
languageCode: language.code
3438
}))
35-
})
36-
.flat()
37-
localizedPaths = await filterLimit(
38-
localizedPaths,
39-
FILE_READ_LIMIT,
40-
async ({ localizedPath }) => Page.exists(localizedPath)
41-
)
42-
const localizedPages = await mapLimit(
43-
localizedPaths,
44-
FILE_READ_LIMIT,
45-
async ({ basePath, relativePath, languageCode }) =>
46-
await Page.init({ basePath, relativePath, languageCode })
47-
)
48-
pageList.push(...localizedPages)
39+
}
40+
}
4941

5042
return pageList
5143
}

tests/browser/browser.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ const sleep = require('await-sleep')
33
const querystring = require('querystring')
44

55
describe('homepage', () => {
6-
jest.setTimeout(60 * 1000)
7-
86
test('should be titled "GitHub Documentation"', async () => {
97
await page.goto('http://localhost:4001')
108
await expect(page.title()).resolves.toMatch('GitHub Documentation')
119
})
1210
})
1311

1412
describe('algolia browser search', () => {
15-
jest.setTimeout(60 * 1000)
16-
1713
it('works on the homepage', async () => {
1814
await page.goto('http://localhost:4001/en')
1915
await page.click('#search-input-container input[type="search"]')

tests/content/crowdin-config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const ignoredPagePaths = config.files[0].ignore
44
const ignoredDataPaths = config.files[2].ignore
55

66
describe('crowdin.yml config file', () => {
7-
jest.setTimeout(60 * 1000)
8-
97
let pages
108
beforeAll(async (done) => {
119
pages = await loadPages()

tests/content/site-data-references.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const fs = require('fs').promises
77
const path = require('path')
88

99
describe('data references', () => {
10-
jest.setTimeout(60 * 1000)
11-
1210
let data, pages
1311

1412
beforeAll(async (done) => {

tests/routing/redirects.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ describe('redirects', () => {
1717
done()
1818
})
1919

20-
test('page.redirects is an array', async () => {
21-
const page = await Page.init({
20+
test('page.redirects is an array', () => {
21+
const page = new Page({
2222
relativePath: 'github/collaborating-with-issues-and-pull-requests/about-branches.md',
2323
basePath: path.join(__dirname, '../../content'),
2424
languageCode: 'en'
2525
})
2626
expect(isPlainObject(page.redirects)).toBe(true)
2727
})
2828

29-
test('dotcom homepage page.redirects', async () => {
30-
const page = await Page.init({
29+
test('dotcom homepage page.redirects', () => {
30+
const page = new Page({
3131
relativePath: 'github/index.md',
3232
basePath: path.join(__dirname, '../../content'),
3333
languageCode: 'en'
@@ -41,7 +41,7 @@ describe('redirects', () => {
4141
})
4242

4343
test('converts single `redirect_from` strings values into arrays', async () => {
44-
const page = await Page.init({
44+
const page = new Page({
4545
relativePath: 'github/collaborating-with-issues-and-pull-requests/about-conversations-on-github.md',
4646
basePath: path.join(__dirname, '../../content'),
4747
languageCode: 'en'

tests/unit/find-page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('find page', () => {
88
jest.setTimeout(1000 * 1000)
99

1010
test('falls back to the English page if it can\'t find a localized page', async () => {
11-
const page = await Page.init({
11+
const page = new Page({
1212
relativePath: 'page-that-does-not-exist-in-translations-dir.md',
1313
basePath: path.join(__dirname, '../fixtures'),
1414
languageCode: 'en'
@@ -24,7 +24,7 @@ describe('find page', () => {
2424
})
2525

2626
test('follows redirects', async () => {
27-
const page = await Page.init({
27+
const page = new Page({
2828
relativePath: 'page-with-redirects.md',
2929
basePath: path.join(__dirname, '../fixtures'),
3030
languageCode: 'en'

tests/unit/liquid-helpers.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const { set } = require('lodash')
55
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
66

77
describe('liquid helper tags', () => {
8-
jest.setTimeout(60 * 1000)
9-
108
const context = {}
119
let pageMap
1210
beforeAll(async (done) => {

0 commit comments

Comments
 (0)