Skip to content

Commit

Permalink
fix(types): pass types through memoize properly (#10567)
Browse files Browse the repository at this point in the history
Co-authored-by: Claas Augner <caugner@mozilla.com>
  • Loading branch information
LeoMcA and caugner authored Mar 5, 2024
1 parent e606646 commit ed9cbf3
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 172 deletions.
16 changes: 10 additions & 6 deletions build/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export async function buildBlogPosts(options: {

const url = `/${locale}/blog/${blogMeta.slug}/`;
const renderUrl = `/${locale}/blog/${blogMeta.slug}`;
const renderDoc = {
const renderDoc: BlogPostDoc = {
url: renderUrl,
rawBody: body,
metadata: { locale, ...blogMeta },
Expand Down Expand Up @@ -344,11 +344,11 @@ export async function buildBlogPosts(options: {
}
}

interface BlogPostDoc {
export interface BlogPostDoc {
url: string;
rawBody: string;
metadata: BlogPostMetadata & { locale: string };
isMarkdown: boolean;
isMarkdown: true;
fileInfo: {
path: string;
};
Expand All @@ -368,7 +368,7 @@ export async function buildPost(
let $ = null;
const liveSamples: LiveSample[] = [];

[$] = await kumascript.render(document.url, {}, document as any);
[$] = await kumascript.render(document.url, {}, document);

const liveSamplePages = await kumascript.buildLiveSamplePages(
document.url,
Expand Down Expand Up @@ -449,8 +449,12 @@ export async function buildBlogFeed(options: { verbose?: boolean }) {
description: post.description,
author: [
{
name: post.author?.name || "The MDN Team",
link: post.author?.link,
name:
(typeof post.author === "string"
? post.author
: post.author?.name) || "The MDN Team",
link:
typeof post.author === "string" ? post.author : post.author?.link,
},
],
date: new Date(post.date),
Expand Down
4 changes: 2 additions & 2 deletions build/curriculum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { memoize, slugToFolder } from "../content/utils.js";
import { renderHTML } from "../ssr/dist/main.js";
import { CheerioAPI } from "cheerio";

export const allFiles: () => string[] = memoize(async () => {
export const allFiles = memoize(async () => {
const api = new fdir()
.withFullPaths()
.withErrors()
Expand All @@ -49,7 +49,7 @@ export const allFiles: () => string[] = memoize(async () => {
return (await api.withPromise()).sort();
});

export const buildIndex: () => CurriculumMetaData[] = memoize(async () => {
export const buildIndex = memoize(async () => {
const files = await allFiles();
const modules = await Promise.all(
files.map(
Expand Down
Loading

0 comments on commit ed9cbf3

Please sign in to comment.