-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: reload siteConfig.js automatically when locally served page is refreshed #1509
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,13 @@ | |
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const CWD = process.cwd(); | ||
|
||
const React = require('react'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const metadataUtils = require('./metadataUtils'); | ||
const {replaceAssetsLink} = require('./utils.js'); | ||
const {renderToStaticMarkupWithDoctype} = require('./renderUtils'); | ||
const loadConfig = require('./config'); | ||
|
||
const siteConfig = loadConfig(`${CWD}/siteConfig.js`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. less CWD calls >.< |
||
|
||
function urlToSource(url) { | ||
if (!url || typeof url !== 'string') { | ||
|
@@ -34,14 +31,14 @@ function fileToUrl(file) { | |
.replace(/\.md$/, '.html'); | ||
} | ||
|
||
function getPagesMarkup(numOfBlog, config) { | ||
function getPagesMarkup(numOfBlog, siteConfig) { | ||
const BlogPageLayout = require('../core/BlogPageLayout.js'); | ||
const blogPages = {}; | ||
const perPage = 10; | ||
for (let page = 0; page < Math.ceil(numOfBlog / perPage); page++) { | ||
const metadata = {page, perPage}; | ||
const blogPageComp = ( | ||
<BlogPageLayout metadata={metadata} language="en" config={config} /> | ||
<BlogPageLayout metadata={metadata} language="en" config={siteConfig} /> | ||
); | ||
const str = renderToStaticMarkupWithDoctype(blogPageComp); | ||
const pagePath = `${page > 0 ? `page${page + 1}` : ''}/index.html`; | ||
|
@@ -50,7 +47,7 @@ function getPagesMarkup(numOfBlog, config) { | |
return blogPages; | ||
} | ||
|
||
function getMetadata(file) { | ||
function getMetadata(file, siteConfig) { | ||
if (!file || !fs.existsSync(file)) { | ||
return null; | ||
} | ||
|
@@ -71,14 +68,14 @@ function getMetadata(file) { | |
return metadata; | ||
} | ||
|
||
function getPostMarkup(file, config) { | ||
const metadata = getMetadata(file); | ||
function getPostMarkup(file, siteConfig) { | ||
const metadata = getMetadata(file, siteConfig); | ||
if (!metadata) { | ||
return null; | ||
} | ||
const BlogPostLayout = require('../core/BlogPostLayout.js'); | ||
const blogPostComp = ( | ||
<BlogPostLayout metadata={metadata} language="en" config={config}> | ||
<BlogPostLayout metadata={metadata} language="en" config={siteConfig}> | ||
{metadata.content} | ||
</BlogPostLayout> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,14 @@ const {join} = require('path'); | |
const {resolve} = require('url'); | ||
const fs = require('fs-extra'); | ||
const React = require('react'); | ||
const loadConfig = require('./config'); | ||
|
||
const siteConfig = loadConfig(`${CWD}/siteConfig.js`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No more cwd calls |
||
const env = require('./env.js'); | ||
const {renderToStaticMarkupWithDoctype} = require('./renderUtils'); | ||
const readMetadata = require('./readMetadata.js'); | ||
const {insertTOC} = require('../core/toc.js'); | ||
const {replaceAssetsLink} = require('./utils.js'); | ||
const {getPath} = require('../core/utils.js'); | ||
|
||
const docsPart = `${siteConfig.docsUrl ? `${siteConfig.docsUrl}/` : ''}`; | ||
|
||
function getFilePath(metadata) { | ||
if (!metadata) { | ||
return null; | ||
|
@@ -51,7 +47,7 @@ function getFile(metadata) { | |
return fs.readFileSync(file, 'utf8'); | ||
} | ||
|
||
function mdToHtmlify(oldContent, mdToHtml, metadata) { | ||
function mdToHtmlify(oldContent, mdToHtml, metadata, siteConfig) { | ||
/* Store broken links */ | ||
const mdBrokenLinks = []; | ||
|
||
|
@@ -106,12 +102,12 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) { | |
return content; | ||
} | ||
|
||
function getMarkup(rawContent, mdToHtml, metadata) { | ||
function getMarkup(rawContent, mdToHtml, metadata, siteConfig) { | ||
// generate table of contents | ||
let content = insertTOC(rawContent); | ||
|
||
// replace any links to markdown files to their website html links | ||
content = mdToHtmlify(content, mdToHtml, metadata); | ||
content = mdToHtmlify(content, mdToHtml, metadata, siteConfig); | ||
|
||
// replace any relative links to static assets (not in fenced code blocks) to absolute links | ||
const docsAssetsLocation = siteConfig.docsUrl | ||
|
@@ -130,7 +126,8 @@ function getMarkup(rawContent, mdToHtml, metadata) { | |
); | ||
} | ||
|
||
function getRedirectMarkup(metadata) { | ||
function getRedirectMarkup(metadata, siteConfig) { | ||
const docsPart = `${siteConfig.docsUrl ? `${siteConfig.docsUrl}/` : ''}`; | ||
if ( | ||
!env.translation.enabled || | ||
!metadata.permalink.includes(`${docsPart}en`) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise it is ignoring the tests on v1. My bad !!