mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 18:46:57 +02:00
Adds sitemap.xml. Adds 'Help Translate' to translatable strings. Error messages and fn name cleanups. (#136)
* added a note about needing more than one language to be enabled to allow for a drop down * Removing debug statements * Add 'Help Translate' to translatable strings, improves error messages around missing translated strings, calls write-translations on some routes * Adds sitemap.xml to live server and build. Versioning not supported. -- Also did some file name and module cache cleanups.
This commit is contained in:
parent
30eea17a24
commit
bcba05ae03
19 changed files with 495 additions and 245 deletions
|
@ -1,4 +1,5 @@
|
|||
/**
|
||||
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
|
@ -6,6 +7,8 @@
|
|||
*/
|
||||
|
||||
function execute(port) {
|
||||
const extractTranslations = require("../write-translations.js");
|
||||
|
||||
const translation = require("./translation.js");
|
||||
const express = require("express");
|
||||
const React = require("react");
|
||||
|
@ -22,6 +25,8 @@ function execute(port) {
|
|||
const versionFallback = require("./versionFallback");
|
||||
|
||||
const feed = require("./feed.js");
|
||||
const sitemap = require("./sitemap.js");
|
||||
// const sitemap = require("sitemap");
|
||||
|
||||
const CWD = process.cwd();
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
|
@ -53,17 +58,31 @@ function execute(port) {
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
let readMetadata;
|
||||
let readMetadata = require("./readMetadata.js");
|
||||
let Metadata;
|
||||
let MetadataBlog;
|
||||
|
||||
function reloadMetadata() {
|
||||
removeModuleAndChildrenFromCache("./readMetadata.js");
|
||||
readMetadata = require("./readMetadata.js");
|
||||
readMetadata.generateDocsMetadata();
|
||||
readMetadata.generateMetadataDocs();
|
||||
removeModuleAndChildrenFromCache("../core/metadata.js");
|
||||
Metadata = require("../core/metadata.js");
|
||||
}
|
||||
|
||||
function reloadMetadataBlog() {
|
||||
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
||||
removeModuleAndChildrenFromCache("../core/MetadataBlog.js");
|
||||
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
||||
}
|
||||
readMetadata.generateMetadataBlog();
|
||||
MetadataBlog = require("../core/MetadataBlog.js");
|
||||
}
|
||||
|
||||
function reloadSiteConfig() {
|
||||
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||
siteConfig = require(CWD + "/siteConfig.js");
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
const TABLE_OF_CONTENTS_TOKEN = "<AUTOGENERATED_TABLE_OF_CONTENTS>";
|
||||
|
@ -105,9 +124,8 @@ function execute(port) {
|
|||
|
||||
// handle all requests for document pages
|
||||
const app = express().get(/docs\/.*html$/, (req, res, next) => {
|
||||
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||
siteConfig = require(CWD + "/siteConfig.js");
|
||||
|
||||
extractTranslations();
|
||||
reloadSiteConfig();
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
|
||||
reloadMetadata();
|
||||
|
@ -230,6 +248,23 @@ function execute(port) {
|
|||
res.send(renderToStaticMarkup(docComp));
|
||||
});
|
||||
|
||||
app.get("/sitemap.xml", function(req, res) {
|
||||
res.set("Content-Type", "application/xml");
|
||||
|
||||
sitemap(xml => {
|
||||
res.send(xml);
|
||||
});
|
||||
});
|
||||
app.get(/blog\/.*xml$/, (req, res) => {
|
||||
res.set("Content-Type", "application/rss+xml");
|
||||
let parts = req.path.toString().split("blog/");
|
||||
if (parts[1].toLowerCase() == "atom.xml") {
|
||||
res.send(feed("atom"));
|
||||
return;
|
||||
}
|
||||
res.send(feed("rss"));
|
||||
});
|
||||
|
||||
app.get(/blog\/.*xml$/, (req, res) => {
|
||||
res.set("Content-Type", "application/rss+xml");
|
||||
let parts = req.path.toString().split("blog/");
|
||||
|
@ -242,14 +277,9 @@ function execute(port) {
|
|||
|
||||
// handle all requests for blog pages and posts
|
||||
app.get(/blog\/.*html$/, (req, res) => {
|
||||
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||
siteConfig = require(CWD + "/siteConfig.js");
|
||||
if (fs.existsSync(__dirname + "/../core/MetadataBlog.js")) {
|
||||
removeModuleAndChildrenFromCache("../core/MetadataBlog.js");
|
||||
fs.removeSync(__dirname + "/../core/MetadataBlog.js");
|
||||
}
|
||||
readMetadata.generateBlogMetadata();
|
||||
const MetadataBlog = require("../core/MetadataBlog.js");
|
||||
extractTranslations();
|
||||
reloadSiteConfig();
|
||||
reloadMetadataBlog();
|
||||
|
||||
// generate all of the blog pages
|
||||
removeModuleAndChildrenFromCache("../core/BlogPageLayout.js");
|
||||
|
@ -318,8 +348,7 @@ function execute(port) {
|
|||
<BlogPostLayout
|
||||
metadata={metadata}
|
||||
language={language}
|
||||
config={siteConfig}
|
||||
>
|
||||
config={siteConfig}>
|
||||
{rawContent}
|
||||
</BlogPostLayout>
|
||||
);
|
||||
|
@ -329,8 +358,8 @@ function execute(port) {
|
|||
|
||||
// handle all other main pages
|
||||
app.get("*.html", (req, res, next) => {
|
||||
removeModuleAndChildrenFromCache(CWD + "/siteConfig.js");
|
||||
siteConfig = require(CWD + "/siteConfig.js");
|
||||
extractTranslations();
|
||||
reloadSiteConfig();
|
||||
|
||||
// look for user provided html file first
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
|
@ -371,7 +400,7 @@ function execute(port) {
|
|||
englishFile = englishFile.replace("/" + language + "/", "/en/");
|
||||
}
|
||||
|
||||
// check for: a file for the page, an english file for page with unspecified language,
|
||||
// check for: a file for the page, an english file for page with unspecified language, or an
|
||||
// english file for the page
|
||||
if (
|
||||
fs.existsSync(userFile) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue