mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +02:00
fix: enable live reloading title of doc (#1507)
* fix: enable live reloading title of doc * fix: removing unnecessary reload statements * fix: only title change should trigger a live reload * fix: adding more properties that triggers a live reload * fix: refactoring
This commit is contained in:
parent
ef1af0a5be
commit
bff9a53095
1 changed files with 22 additions and 5 deletions
|
@ -89,6 +89,10 @@ function execute(port, host) {
|
||||||
MetadataBlog = require(join('..', 'core', 'MetadataBlog.js'));
|
MetadataBlog = require(join('..', 'core', 'MetadataBlog.js'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reloadTranslations() {
|
||||||
|
removeModuleAndChildrenFromCache('./translation.js');
|
||||||
|
}
|
||||||
|
|
||||||
function requestFile(url, res, notFoundCallback) {
|
function requestFile(url, res, notFoundCallback) {
|
||||||
request.get(url, (error, response, body) => {
|
request.get(url, (error, response, body) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
@ -116,18 +120,31 @@ function execute(port, host) {
|
||||||
|
|
||||||
app.get(routing.docs(siteConfig), (req, res, next) => {
|
app.get(routing.docs(siteConfig), (req, res, next) => {
|
||||||
const url = decodeURI(req.path.toString().replace(siteConfig.baseUrl, ''));
|
const url = decodeURI(req.path.toString().replace(siteConfig.baseUrl, ''));
|
||||||
const metadata =
|
const metakey = Object.keys(Metadata).find(
|
||||||
Metadata[
|
id => Metadata[id].permalink === url,
|
||||||
Object.keys(Metadata).find(id => Metadata[id].permalink === url)
|
);
|
||||||
];
|
|
||||||
|
let metadata = Metadata[metakey];
|
||||||
|
|
||||||
const file = docs.getFile(metadata);
|
const file = docs.getFile(metadata);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const {rawContent, metadata: rawMetadata} = metadataUtils.extractMetadata(
|
||||||
|
file,
|
||||||
|
);
|
||||||
|
|
||||||
|
// if any of the followings is changed, reload the metadata
|
||||||
|
const reloadTriggers = ['sidebar_label', 'hide_title', 'title'];
|
||||||
|
if (reloadTriggers.some(key => metadata[key] !== rawMetadata[key])) {
|
||||||
|
reloadMetadata();
|
||||||
|
extractTranslations();
|
||||||
|
reloadTranslations();
|
||||||
|
metadata = Metadata[metakey];
|
||||||
|
}
|
||||||
|
|
||||||
reloadSiteConfig();
|
reloadSiteConfig();
|
||||||
const rawContent = metadataUtils.extractMetadata(file).rawContent;
|
|
||||||
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
|
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
|
||||||
const mdToHtml = metadataUtils.mdToHtml(Metadata, siteConfig);
|
const mdToHtml = metadataUtils.mdToHtml(Metadata, siteConfig);
|
||||||
res.send(docs.getMarkup(rawContent, mdToHtml, metadata, siteConfig));
|
res.send(docs.getMarkup(rawContent, mdToHtml, metadata, siteConfig));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue