From f35c21a8c046cc0f28202210db46ab8a5777c801 Mon Sep 17 00:00:00 2001 From: Foster Hangdaan Date: Fri, 6 Sep 2024 11:05:02 -0400 Subject: [PATCH] Fix TypeScript errors --- _components/PostListItem.tsx | 16 ++++++---------- _components/footer.tsx | 2 +- _components/header.tsx | 12 +----------- _config.ts | 20 +++++++++++++------- _includes/layouts/base.tsx | 2 +- _includes/layouts/post.tsx | 18 +++++++++++++++++- blog/index.tsx | 26 ++++++++++++-------------- deno.json | 7 ++++--- deno.lock | Bin 87618 -> 91447 bytes index.tsx | 34 +++++++++++++++++----------------- 10 files changed, 72 insertions(+), 65 deletions(-) diff --git a/_components/PostListItem.tsx b/_components/PostListItem.tsx index 06a4098..a339e9b 100644 --- a/_components/PostListItem.tsx +++ b/_components/PostListItem.tsx @@ -1,24 +1,20 @@ -interface Props { - post: any; -} - -export default function (props: Props) { +export default function (data: Lume.Data) { return (
  • - - {props.post.data.title} + + {data.post.data.title} -

    {props.post.data.description}

    +

    {data.post.data.description}

  • ); } diff --git a/_components/footer.tsx b/_components/footer.tsx index 29eec54..3d28065 100644 --- a/_components/footer.tsx +++ b/_components/footer.tsx @@ -1,4 +1,4 @@ -export default function ({ comp }) { +export default function ({ comp }: Lume.Data) { const iconStyle = { filter: "var(--filter-fg)", }; diff --git a/_components/header.tsx b/_components/header.tsx index 104fe4c..ceaaf54 100644 --- a/_components/header.tsx +++ b/_components/header.tsx @@ -1,14 +1,4 @@ -export interface Props { - title: string; - description?: string; - author?: { - name: string; - }; - date: Date; - comp: any; -} - -export default function (props: Props) { +export default function (props: Lume.Data) { const dateFormatted = Intl.DateTimeFormat("en-CA", { dateStyle: "long" }) .format(props.date); return ( diff --git a/_config.ts b/_config.ts index 41919cd..7d48713 100644 --- a/_config.ts +++ b/_config.ts @@ -4,8 +4,8 @@ import nav from "lume/plugins/nav.ts"; import sass from "lume/plugins/sass.ts"; import feed from "lume/plugins/feed.ts"; import code_highlight from "lume/plugins/code_highlight.ts"; -import toc from "https://deno.land/x/lume_markdown_plugins@v0.6.0/toc.ts"; -import footnotes from "https://deno.land/x/lume_markdown_plugins@v0.6.0/footnotes.ts"; +import toc from "lume-markdown-plugins/toc.ts"; +import footnotes from "lume-markdown-plugins/footnotes.ts"; import lang_typescript from "npm:highlight.js/lib/languages/typescript"; import lang_javascript from "npm:highlight.js/lib/languages/javascript"; @@ -63,15 +63,21 @@ site.process([".html"], (pages) => { // NOTE: This is a hack to append a class to JS doctrings so that we // can style them. If only the Hightlight.js plugin could be configured // to do this instead. - page.document?.getElementsByClassName("hljs-comment").forEach( - (codeCommentElement) => { + if (page.document) { + for ( + const codeCommentElement of page.document.getElementsByClassName( + "hljs-comment", + ) + ) { const docStringRegex = /^\/\*\*.*\*\/$/gsm; - const matchResult = codeCommentElement.innerText.match(docStringRegex); + const matchResult = codeCommentElement.textContent?.match( + docStringRegex, + ); if (matchResult) { codeCommentElement.classList.add("docstring"); } - }, - ); + } + } }); }); diff --git a/_includes/layouts/base.tsx b/_includes/layouts/base.tsx index b623569..a2dca1b 100644 --- a/_includes/layouts/base.tsx +++ b/_includes/layouts/base.tsx @@ -1,5 +1,5 @@ export default function ( - { title, description, children, comp, metas, links, author, date }, + { title, description, children, comp, metas, links, author, date }: Lume.Data, ) { return ( diff --git a/_includes/layouts/post.tsx b/_includes/layouts/post.tsx index 02f9633..c1326c9 100644 --- a/_includes/layouts/post.tsx +++ b/_includes/layouts/post.tsx @@ -1,6 +1,22 @@ export const layout = "./base.tsx"; -export default function ({ children, toc, footnotes }) { +interface Data { + toc: { + text: string; + slug: string; + children: { + text: string; + slug: string; + }[]; + }[]; + footnotes: { + refId: string; + content: string; + id: string; + }[]; +} + +export default function ({ children, toc, footnotes }: Data & Lume.Data) { return ( <> {toc.length > 0 && diff --git a/blog/index.tsx b/blog/index.tsx index 8df654b..f270767 100644 --- a/blog/index.tsx +++ b/blog/index.tsx @@ -1,19 +1,9 @@ export const title = "Blog"; export const description = "Hello, stranger. Stay a while and listen."; -export default function ({ nav, comp }) { +export default function ({ nav, comp }: Lume.Data) { const { PostListItem } = comp; - const sortPosts = (a, b) => { - if (a.data.date < b.data.date) { - return 1; - } else if (a.data.date > b.data.date) { - return -1; - } else { - return 0; - } - }; - if (!nav.menu("/blog/posts")) { return (
    @@ -32,9 +22,17 @@ export default function ({ nav, comp }) { return ( ); } diff --git a/deno.json b/deno.json index b70aae6..cd8fbd9 100644 --- a/deno.json +++ b/deno.json @@ -2,21 +2,22 @@ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "npm:react", + "jsxImportSourceTypes": "npm:@types/react", "types": [ - "https://unpkg.com/@types/react@18.2.37/index.d.ts", "lume/types.ts" ] }, "tasks": { "lume": "echo \"import 'lume/cli.ts'\" | deno run --allow-write='.' --allow-read='.' --allow-net='deno.land,cdn.deno.land,esm.sh,0.0.0.0:3000,jsr.io,lumeland.github.io' --allow-sys=networkInterfaces --allow-env='LUME_ENV,LUME_LIVE_RELOAD,LUME_LOGS,LUME_NOCACHE,LUME_DRAFTS' -", "build": "deno task lume", - "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", + "check": "deno fmt --check && deno lint && deno check .", "serve": "deno task lume -s", "deploy": "rsync -avh --progress --delete ./_site/ podman:/srv/www/fosterhangdaan.com/" }, "imports": { "react/jsx-runtime": "https://esm.sh/react@18.2.0/jsx-runtime", - "lume/": "https://deno.land/x/lume@v2.2.4/" + "lume/": "https://deno.land/x/lume@v2.2.4/", + "lume-markdown-plugins/": "https://deno.land/x/lume_markdown_plugins@v0.7.1/" }, "fmt": { "exclude": [ diff --git a/deno.lock b/deno.lock index 92fc9c6e8c571b6dbc71131afca0fb3c5890589f..8d43b0036cdf076dd491367abbbac018c21a782c 100644 GIT binary patch delta 2365 zcmaJ?OKe+N8J0^kNlRMNj>=Gx%rp^00Z)9-^PYRUpmyRoapFh(j=NyE=W*jl{JeH; zhs6{$LP$u=j4o0ZNQfm1G@=S3LSg|(!vX{YOIUTq3JI|RAtc0g>~tKU+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S35`s_ z820}t#P-9Zjslj_LQ%vtSCVioJ^ODH*pKd1f#tIR delta 142 zcmV;90CE4f$_2u#1(1%D&;$gNfEEywIRp%`Nm?#{x4JCgJvuZSt1+%U?SrfB$Q0lX{-UI>a7n9Y% wa+VkY2e-Q&0nP}w3MT { - if (a.data.date < b.data.date) { - return 1; - } else if (a.data.date > b.data.date) { - return -1; - } else { - return 0; - } - }; - +export default function (data: Lume.Data) { return ( <>

    @@ -24,7 +14,7 @@ export default function ({ nav }) { times, I help in the battle for an open web and for user privacy by contributing in the development of free and open-source software.

    -

    +

    Contact Me

    @@ -35,7 +25,7 @@ export default function ({ nav }) { If you'd like an encrypted response, you can send me your GPG public key. You can find mine in the GPG Key page.

    -

    +

    Highlighted Projects @@ -78,21 +68,31 @@ export default function ({ nav }) { View all projects

    -

    +

    Latest Blog Posts

      - {nav.menu("/blog/posts").children.sort(sortPosts).slice(0, 5).map(( + {data.nav.menu("/blog/posts")?.children?.sort((a, b) => { + let result = 0; + if (a.data && b.data) { + if (a.data.date < b.data.date) { + result = 1; + } else if (a.data.date > b.data.date) { + result = -1; + } + } + return result; + }).slice(0, 5).map(( post, index, ) => (
    • - {post.data.title} —{" "} + {post.data?.title} —{" "}