Skip to content

Commit

Permalink
Merge pull request github#20257 from github/initialize-pages-for-tran…
Browse files Browse the repository at this point in the history
…slation-paths

Initialize pages for translated paths, not just English
  • Loading branch information
sarahs authored Jul 1, 2021
2 parents c114154 + 2a379f3 commit f7c52b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/create-tree.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const fs = require('fs').promises
const path = require('path')
const Page = require('./page')
const basePath = path.posix.join(__dirname, '..', 'content')

module.exports = async function createTree (originalPath, langObj) {
// This basePath definition is needed both here and in lib/page-data.js because this
// function runs recursively, and the value for originalPath changes on recursive runs.
const basePath = path.posix.join(__dirname, '..', langObj.dir, 'content')

// On recursive runs, this is processing page.children items in `/<link>` format.
// If the path exists as is, assume this is a directory with a child index.md.
// Otherwise, assume it's a child .md file and add `.md` to the path.
Expand All @@ -16,11 +19,10 @@ module.exports = async function createTree (originalPath, langObj) {
}

const relativePath = filepath.replace(`${basePath}/`, '')
const localizedBasePath = path.posix.join(__dirname, '..', langObj.dir, 'content')

// Initialize the Page! This is where the file reads happen.
const page = await Page.init({
basePath: localizedBasePath,
basePath,
relativePath,
languageCode: langObj.code
})
Expand Down
4 changes: 2 additions & 2 deletions lib/page-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const createTree = require('./create-tree')
const renderContent = require('./render-content')
const loadSiteData = require('./site-data')
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
const englishPath = path.posix.join(__dirname, '..', 'content')
const renderOpts = { textOnly: true, encodeEntities: true }

/**
Expand All @@ -19,7 +18,8 @@ async function loadUnversionedTree () {

await Promise.all(Object.values(languages)
.map(async (langObj) => {
unversionedTree[langObj.code] = await createTree(englishPath, langObj)
const localizedContentPath = path.posix.join(__dirname, '..', langObj.dir, 'content')
unversionedTree[langObj.code] = await createTree(localizedContentPath, langObj)
}))

return unversionedTree
Expand Down

0 comments on commit f7c52b0

Please sign in to comment.