mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-29 05:12:52 +00:00
* [v2] tags to doc, same as tags to blog - [IN PROGRESS] - Addition of plugin-content-docs - Addition of DocTagsListPage in `docusaurus-theme-classic` ! Error exists for this commit towards the theme aspect and help required. Commit towards #3434 * docs: make tags list page work * temp: disable onBrokenLinks * theme bootstrap: create DocTagsListPage * DocTagsPage added and functionality too - individual doc tag page added to show docs for that specific tag * Added all Docs Tags Link * add some shared tag utils * move tag tests to _dogfooding * fix type * fix some tests * fix blog test * refactor blog post tags handling * better yaml tag examples * better dogfood md files * refactor and factorize theme tag components * finish DocTagDocListPage * Extract DocItemFooter + add inline tag list * minor fix * better typings * fix versions.test.ts tests * add tests for doc tags * fix tests * test toTagDocListProp * move shared theme code to tagUtils * Add new theme translation keys * move common theme code to tagUtils + add tests * update-code-translations should handle theme-common * update french translation * revert add translation * fix pluralization problem in theme.docs.tagDocListPageTitle * add theme component configuration options * add more tags tests * add documentation for docs tagging Co-authored-by: slorber <lorber.sebastien@gmail.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
import Joi from './Joi';
|
|
import {isValidPathname} from '@docusaurus/utils';
|
|
import type {Tag} from '@docusaurus/utils';
|
|
import {JoiFrontMatter} from './JoiFrontMatter';
|
|
|
|
export const PluginIdSchema = Joi.string()
|
|
.regex(/^[a-zA-Z_-]+$/)
|
|
// duplicate core constant, otherwise cyclic dependency is created :(
|
|
.default('default');
|
|
|
|
const MarkdownPluginsSchema = Joi.array()
|
|
.items(
|
|
Joi.array().ordered(Joi.function().required(), Joi.object().required()),
|
|
Joi.function(),
|
|
Joi.object(),
|
|
)
|
|
.default([]);
|
|
|
|
export const RemarkPluginsSchema = MarkdownPluginsSchema;
|
|
export const RehypePluginsSchema = MarkdownPluginsSchema;
|
|
|
|
export const AdmonitionsSchema = Joi.object().default({});
|
|
|
|
// TODO how can we make this emit a custom error message :'(
|
|
// Joi is such a pain, good luck to annoying trying to improve this
|
|
export const URISchema = Joi.alternatives(
|
|
Joi.string().uri({allowRelative: true}),
|
|
// This custom validation logic is required notably because Joi does not accept paths like /a/b/c ...
|
|
Joi.custom((val, helpers) => {
|
|
try {
|
|
const url = new URL(val);
|
|
if (url) {
|
|
return val;
|
|
} else {
|
|
return helpers.error('any.invalid');
|
|
}
|
|
} catch {
|
|
return helpers.error('any.invalid');
|
|
}
|
|
}),
|
|
);
|
|
|
|
export const PathnameSchema = Joi.string()
|
|
.custom((val) => {
|
|
if (!isValidPathname(val)) {
|
|
throw new Error();
|
|
} else {
|
|
return val;
|
|
}
|
|
})
|
|
.message(
|
|
'{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
|
|
);
|
|
|
|
export const FrontMatterTagsSchema = JoiFrontMatter.array().items(
|
|
JoiFrontMatter.alternatives().try(
|
|
JoiFrontMatter.string().required(),
|
|
JoiFrontMatter.object<Tag>({
|
|
label: JoiFrontMatter.string().required(),
|
|
permalink: JoiFrontMatter.string().required(),
|
|
}).required(),
|
|
),
|
|
);
|