mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
Code cleanups for consistency & adds Docusaurus to meta tags (#138)
* Add a made with Docusaurus meta tag * Code cleanups and changes for clarity * Add back pages string extraction
This commit is contained in:
parent
fd05bb3239
commit
a4695a3083
4 changed files with 43 additions and 14 deletions
|
@ -25,6 +25,7 @@ class Head extends React.Component {
|
|||
<meta httpEquiv="X-UA-Compatible" content="IE=edge, chrome=1" />
|
||||
<title>{this.props.title}</title>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content="Docusaurus" />
|
||||
<meta property="og:title" content={this.props.title} />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content={this.props.url} />
|
||||
|
|
|
@ -107,7 +107,6 @@ function extractMetadata(content) {
|
|||
} catch (e) {}
|
||||
metadata[key] = value;
|
||||
}
|
||||
|
||||
return { metadata, rawContent: both.content };
|
||||
}
|
||||
|
||||
|
|
|
@ -121,14 +121,15 @@ function execute(port) {
|
|||
console.log("server.js triggered...");
|
||||
|
||||
reloadMetadata();
|
||||
|
||||
// handle all requests for document pages
|
||||
const app = express().get(/docs\/.*html$/, (req, res, next) => {
|
||||
reloadMetadataBlog();
|
||||
extractTranslations();
|
||||
reloadSiteConfig();
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
|
||||
reloadMetadata();
|
||||
// handle all requests for document pages
|
||||
const app = express();
|
||||
|
||||
app.get(/docs\/.*html$/, (req, res, next) => {
|
||||
let url = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
|
||||
// links is a map from a permalink to an id for each document
|
||||
let links = {};
|
||||
|
@ -240,7 +241,11 @@ function execute(port) {
|
|||
}
|
||||
|
||||
const docComp = (
|
||||
<DocsLayout metadata={metadata} language={language} config={siteConfig} Doc={Doc}>
|
||||
<DocsLayout
|
||||
metadata={metadata}
|
||||
language={language}
|
||||
config={siteConfig}
|
||||
Doc={Doc}>
|
||||
{rawContent}
|
||||
</DocsLayout>
|
||||
);
|
||||
|
@ -277,10 +282,6 @@ function execute(port) {
|
|||
|
||||
// handle all requests for blog pages and posts
|
||||
app.get(/blog\/.*html$/, (req, res) => {
|
||||
extractTranslations();
|
||||
reloadSiteConfig();
|
||||
reloadMetadataBlog();
|
||||
|
||||
// generate all of the blog pages
|
||||
removeModuleAndChildrenFromCache("../core/BlogPageLayout.js");
|
||||
const BlogPageLayout = require("../core/BlogPageLayout.js");
|
||||
|
@ -358,9 +359,6 @@ function execute(port) {
|
|||
|
||||
// handle all other main pages
|
||||
app.get("*.html", (req, res, next) => {
|
||||
extractTranslations();
|
||||
reloadSiteConfig();
|
||||
|
||||
// look for user provided html file first
|
||||
let htmlFile = req.path.toString().replace(siteConfig.baseUrl, "");
|
||||
htmlFile = CWD + "/pages/" + htmlFile;
|
||||
|
|
|
@ -85,6 +85,37 @@ function execute() {
|
|||
});
|
||||
});
|
||||
|
||||
// go through pages to look for text inside translate tags
|
||||
files = glob.sync(CWD + "/pages/en/**");
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".js") {
|
||||
const ast = babylon.parse(fs.readFileSync(file, "utf8"), {
|
||||
plugins: ["jsx"]
|
||||
});
|
||||
traverse(ast, {
|
||||
enter(path) {
|
||||
if (
|
||||
path.node.type === "JSXElement" &&
|
||||
path.node.openingElement.name.name === "translate"
|
||||
) {
|
||||
const text = path.node.children[0].value
|
||||
.trim()
|
||||
.replace(/\s+/g, " ");
|
||||
let description = "no description given";
|
||||
const attributes = path.node.openingElement.attributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name.name === "desc") {
|
||||
description = attributes[i].value.value;
|
||||
}
|
||||
}
|
||||
translations["pages-strings"][text + "|" + description] = text;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Manually add 'Help Translate' to en.json
|
||||
translations["pages-strings"][
|
||||
"Help Translate|recruit community translators for your project"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue