mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
Refactor + add more tests (Part 1) (#847)
* Refactor mdToHtml out * Refactor routing + move it to server instead of core * Refactor & Add more tests for server utils * Refactor isSeparateCss function from server & generate * Refactor insertTableOfContents from server & generate + add tests * undo small nits
This commit is contained in:
parent
a7a214fb3a
commit
defcbcc8ee
14 changed files with 322 additions and 235 deletions
46
lib/server/routing.js
Normal file
46
lib/server/routing.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
function blog(baseUrl) {
|
||||
return new RegExp(`^${baseUrl}blog/.*html$`);
|
||||
}
|
||||
|
||||
function docs(baseUrl) {
|
||||
return new RegExp(`^${baseUrl}docs/.*html$`);
|
||||
}
|
||||
|
||||
function dotfiles() {
|
||||
return /(?!.*html$)^\/.*\.[^\n/]+$/;
|
||||
}
|
||||
|
||||
function feed(baseUrl) {
|
||||
return new RegExp(`^${baseUrl}blog/(feed.xml|atom.xml)$`);
|
||||
}
|
||||
|
||||
function noExtension() {
|
||||
return /\/[^.]*\/?$/;
|
||||
}
|
||||
|
||||
function page(baseUrl) {
|
||||
const gr = regex => regex.toString().replace(/(^\/|\/$)/gm, '');
|
||||
return new RegExp(
|
||||
`(?!${gr(docs(baseUrl))}|${gr(blog(baseUrl))})^${baseUrl}.*.html$`
|
||||
);
|
||||
}
|
||||
|
||||
function sitemap(baseUrl) {
|
||||
return new RegExp(`^${baseUrl}sitemap.xml$`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
blog,
|
||||
docs,
|
||||
dotfiles,
|
||||
feed,
|
||||
page,
|
||||
noExtension,
|
||||
sitemap,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue