mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-17 00:35:50 +02:00
refactor: enable a few TS flags (#6852)
* refactor: enable a few TS flags * refactor * revert to working version * fix * better * change
This commit is contained in:
parent
9f925a42bf
commit
4db0c620de
71 changed files with 210 additions and 174 deletions
|
@ -6,11 +6,11 @@
|
|||
*/
|
||||
|
||||
export const NODE_MAJOR_VERSION = parseInt(
|
||||
process.versions.node.split('.')[0],
|
||||
process.versions.node.split('.')[0]!,
|
||||
10,
|
||||
);
|
||||
export const NODE_MINOR_VERSION = parseInt(
|
||||
process.versions.node.split('.')[1],
|
||||
process.versions.node.split('.')[1]!,
|
||||
10,
|
||||
);
|
||||
|
||||
|
|
|
@ -48,12 +48,13 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
|||
let lastCodeFence = '';
|
||||
const lines = fileString.split('\n').map((line) => {
|
||||
if (line.trim().startsWith('```')) {
|
||||
const codeFence = line.trim().match(/^`+/)![0]!;
|
||||
if (!fencedBlock) {
|
||||
fencedBlock = true;
|
||||
[lastCodeFence] = line.trim().match(/^`+/)!;
|
||||
lastCodeFence = codeFence;
|
||||
// If we are in a ````-fenced block, all ``` would be plain text instead
|
||||
// of fences
|
||||
} else if (line.trim().match(/^`+/)![0].length >= lastCodeFence.length) {
|
||||
} else if (codeFence.length >= lastCodeFence.length) {
|
||||
fencedBlock = false;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
|||
let mdMatch = mdRegex.exec(modifiedLine);
|
||||
while (mdMatch !== null) {
|
||||
// Replace it to correct html link.
|
||||
const mdLink = mdMatch.groups!.filename;
|
||||
const mdLink = mdMatch.groups!.filename!;
|
||||
|
||||
const sourcesToTry = [
|
||||
path.resolve(path.dirname(filePath), decodeURIComponent(mdLink)),
|
||||
|
|
|
@ -18,8 +18,8 @@ export function parseMarkdownHeadingId(heading: string): {
|
|||
const matches = customHeadingIdRegex.exec(heading);
|
||||
if (matches) {
|
||||
return {
|
||||
text: matches.groups!.text,
|
||||
id: matches.groups!.id,
|
||||
text: matches.groups!.text!,
|
||||
id: matches.groups!.id!,
|
||||
};
|
||||
}
|
||||
return {text: heading, id: undefined};
|
||||
|
@ -51,14 +51,13 @@ export function createExcerpt(fileString: string): string | undefined {
|
|||
|
||||
// Skip code block line.
|
||||
if (fileLine.trim().startsWith('```')) {
|
||||
const codeFence = fileLine.trim().match(/^`+/)![0]!;
|
||||
if (!inCode) {
|
||||
inCode = true;
|
||||
[lastCodeFence] = fileLine.trim().match(/^`+/)!;
|
||||
lastCodeFence = codeFence;
|
||||
// If we are in a ````-fenced block, all ``` would be plain text instead
|
||||
// of fences
|
||||
} else if (
|
||||
fileLine.trim().match(/^`+/)![0].length >= lastCodeFence.length
|
||||
) {
|
||||
} else if (codeFence.length >= lastCodeFence.length) {
|
||||
inCode = false;
|
||||
}
|
||||
continue;
|
||||
|
|
|
@ -80,13 +80,13 @@ export function groupTaggedItems<Item>(
|
|||
// TODO: it's not really clear what should be the behavior if 2 items have
|
||||
// the same tag but the permalink is different for each
|
||||
// For now, the first tag found wins
|
||||
result[tag.permalink] = result[tag.permalink] ?? {
|
||||
result[tag.permalink] ??= {
|
||||
tag,
|
||||
items: [],
|
||||
};
|
||||
|
||||
// Add item to group
|
||||
result[tag.permalink].items.push(item);
|
||||
result[tag.permalink]!.items.push(item);
|
||||
}
|
||||
|
||||
items.forEach((item) => {
|
||||
|
|
|
@ -15,10 +15,17 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|||
let hasStartingSlash = false;
|
||||
let hasEndingSlash = false;
|
||||
|
||||
const isNonEmptyArray = (arr: string[]): arr is [string, ...string[]] =>
|
||||
arr.length > 0;
|
||||
|
||||
if (!isNonEmptyArray(urls)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// If the first part is a plain protocol, we combine it with the next part.
|
||||
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
||||
const first = urls.shift();
|
||||
if (first!.startsWith('file:') && urls[0].startsWith('/')) {
|
||||
const first = urls.shift()!;
|
||||
if (first.startsWith('file:') && urls[0].startsWith('/')) {
|
||||
// Force a double slash here, else we lose the information that the next
|
||||
// segment is an absolute path
|
||||
urls[0] = `${first}//${urls[0]}`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue