mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 06:50:36 +02:00
fix: reload siteConfig.js automatically when locally served page is refreshed (#1509)
* fix: livereload siteConfig * fix test * nits
This commit is contained in:
parent
aa157969cf
commit
166816af40
11 changed files with 53 additions and 42 deletions
|
@ -60,6 +60,18 @@ function execute(port, host) {
|
|||
let MetadataBlog;
|
||||
let siteConfig;
|
||||
|
||||
function reloadSiteConfig() {
|
||||
const siteConfigPath = join(CWD, 'siteConfig.js');
|
||||
removeModuleAndChildrenFromCache(siteConfigPath);
|
||||
const oldBaseUrl = siteConfig && siteConfig.baseUrl;
|
||||
siteConfig = loadConfig(siteConfigPath);
|
||||
|
||||
if (oldBaseUrl && oldBaseUrl !== siteConfig.baseUrl) {
|
||||
console.log('Base url has changed. Please restart server ...');
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
function reloadMetadata() {
|
||||
removeModuleAndChildrenFromCache('./readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
|
@ -72,16 +84,11 @@ function execute(port, host) {
|
|||
removeModuleAndChildrenFromCache(join('..', 'core', 'MetadataBlog.js'));
|
||||
fs.removeSync(join(__dirname, '..', 'core', 'MetadataBlog.js'));
|
||||
}
|
||||
readMetadata.generateMetadataBlog();
|
||||
reloadSiteConfig();
|
||||
readMetadata.generateMetadataBlog(siteConfig);
|
||||
MetadataBlog = require(join('..', 'core', 'MetadataBlog.js'));
|
||||
}
|
||||
|
||||
function reloadSiteConfig() {
|
||||
const siteConfigPath = join(CWD, 'siteConfig.js');
|
||||
removeModuleAndChildrenFromCache(siteConfigPath);
|
||||
siteConfig = loadConfig(siteConfigPath);
|
||||
}
|
||||
|
||||
function requestFile(url, res, notFoundCallback) {
|
||||
request.get(url, (error, response, body) => {
|
||||
if (!error) {
|
||||
|
@ -119,10 +126,11 @@ function execute(port, host) {
|
|||
next();
|
||||
return;
|
||||
}
|
||||
reloadSiteConfig();
|
||||
const rawContent = metadataUtils.extractMetadata(file).rawContent;
|
||||
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
|
||||
const mdToHtml = metadataUtils.mdToHtml(Metadata, siteConfig);
|
||||
res.send(docs.getMarkup(rawContent, mdToHtml, metadata));
|
||||
res.send(docs.getMarkup(rawContent, mdToHtml, metadata, siteConfig));
|
||||
});
|
||||
|
||||
app.get(routing.sitemap(siteConfig), (req, res) => {
|
||||
|
@ -177,6 +185,7 @@ function execute(port, host) {
|
|||
});
|
||||
|
||||
app.get(routing.page(siteConfig), (req, res, next) => {
|
||||
reloadSiteConfig();
|
||||
// Look for user-provided HTML file first.
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, '');
|
||||
htmlFile = join(CWD, 'pages', htmlFile);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue