mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +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'));
|
||||
}
|
||||
|
||||
function reloadTranslations() {
|
||||
removeModuleAndChildrenFromCache('./translation.js');
|
||||
}
|
||||
|
||||
function requestFile(url, res, notFoundCallback) {
|
||||
request.get(url, (error, response, body) => {
|
||||
if (!error) {
|
||||
|
@ -116,18 +120,31 @@ function execute(port, host) {
|
|||
|
||||
app.get(routing.docs(siteConfig), (req, res, next) => {
|
||||
const url = decodeURI(req.path.toString().replace(siteConfig.baseUrl, ''));
|
||||
const metadata =
|
||||
Metadata[
|
||||
Object.keys(Metadata).find(id => Metadata[id].permalink === url)
|
||||
];
|
||||
const metakey = Object.keys(Metadata).find(
|
||||
id => Metadata[id].permalink === url,
|
||||
);
|
||||
|
||||
let metadata = Metadata[metakey];
|
||||
|
||||
const file = docs.getFile(metadata);
|
||||
if (!file) {
|
||||
next();
|
||||
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();
|
||||
const rawContent = metadataUtils.extractMetadata(file).rawContent;
|
||||
removeModuleAndChildrenFromCache('../core/DocsLayout.js');
|
||||
const mdToHtml = metadataUtils.mdToHtml(Metadata, siteConfig);
|
||||
res.send(docs.getMarkup(rawContent, mdToHtml, metadata, siteConfig));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue