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:
Joshua Chen 2022-03-06 13:09:10 +08:00 committed by GitHub
parent 9f925a42bf
commit 4db0c620de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 210 additions and 174 deletions

View file

@ -139,10 +139,10 @@ export function parseBlogFileName(
if (dateFilenameMatch) {
const {folder, text, date: dateString} = dateFilenameMatch.groups!;
// Always treat dates as UTC by adding the `Z`
const date = new Date(`${dateString}Z`);
const slugDate = dateString.replace(/-/g, '/');
const slug = `/${slugDate}/${folder}${text}`;
return {date, text, slug};
const date = new Date(`${dateString!}Z`);
const slugDate = dateString!.replace(/-/g, '/');
const slug = `/${slugDate}/${folder!}${text!}`;
return {date, text: text!, slug};
}
const text = blogSourceRelative.replace(/(?:\/index)?\.mdx?$/, '');
const slug = `/${text}`;

View file

@ -307,7 +307,7 @@ export default async function pluginContentBlog(
({
content: {
__import: true,
path: blogItemsToMetadata[postID].source,
path: blogItemsToMetadata[postID]!.source,
query: {
truncated: true,
},
@ -359,7 +359,7 @@ export default async function pluginContentBlog(
modules: {
sidebar: aliasedSource(sidebarProp),
items: items.map((postID) => {
const blogPostMetadata = blogItemsToMetadata[postID];
const blogPostMetadata = blogItemsToMetadata[postID]!;
return {
content: {
__import: true,

View file

@ -19,8 +19,9 @@ function translateListPage(
items,
metadata: {
...metadata,
blogTitle: translations.title.message,
blogDescription: translations.description.message,
blogTitle: translations.title?.message ?? page.metadata.blogTitle,
blogDescription:
translations.description?.message ?? page.metadata.blogDescription,
},
};
});
@ -52,10 +53,14 @@ export function translateContent(
content: BlogContent,
translationFiles: TranslationFiles,
): BlogContent {
const [{content: optionsTranslations}] = translationFiles;
if (translationFiles.length === 0) {
return content;
}
const {content: optionsTranslations} = translationFiles[0]!;
return {
...content,
blogSidebarTitle: optionsTranslations['sidebar.title'].message,
blogSidebarTitle:
optionsTranslations['sidebar.title']?.message ?? content.blogSidebarTitle,
blogListPaginated: translateListPage(
content.blogListPaginated,
optionsTranslations,