Skip to content

Commit

Permalink
Support per-post custom font and change global font to Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Aug 2, 2024
1 parent ed20672 commit e0a9a5b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions frontmatter.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"title": "draft",
"name": "draft",
"type": "boolean"
},
{
"title": "font",
"name": "font",
"type": "string"
}
]
}
Expand Down
Binary file added public/fonts/USDeclaration.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions src/components/PostCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props {
description: string;
words: number;
draft: boolean;
font: string;
style: string;
}
const { entry, title, url, published, tags, category, image, description, words, style } = Astro.props;
Expand Down
3 changes: 2 additions & 1 deletion src/components/PostPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let delay = 0
const interval = 50
---
<div class="transition flex flex-col rounded-[var(--radius-large)] bg-[var(--card-bg)] py-1 md:py-0 md:bg-transparent md:gap-4 mb-4">
{page.data.map((entry: { data: { draft: boolean; title: string; tags: string[]; category: string; published: Date; image: string; description: string; }; slug: string; }) => {
{page.data.map((entry: { data: { draft: boolean; title: string; tags: string[]; category: string; published: Date; image: string; description: string; font: string }; slug: string; }) => {
return (
<PostCard
entry={entry}
Expand All @@ -20,6 +20,7 @@ const interval = 50
image={entry.data.image}
description={entry.data.description}
draft={entry.data.draft}
font={entry.data.font}
class:list="onload-animation"
style={`animation-delay: calc(var(--content-delay) + ${delay++ * interval}ms);`}
></PostCard>
Expand Down
1 change: 1 addition & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const postsCollection = defineCollection({
image: z.string().optional(),
tags: z.array(z.string()).optional(),
category: z.string().optional(),
font: z.string().optional(),
}),
})
export const collections = {
Expand Down
3 changes: 2 additions & 1 deletion src/content/posts/declaration-of-independence/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ description: |
image: './cover.png'
tags: [ "Leadership" ]
category: 'Leadership'
draft: false
draft: false
font: USDeclaration
---

![Error loading declaration-of-independence.png](./declaration-of-independence.png)
Expand Down
19 changes: 16 additions & 3 deletions src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,23 @@ const jsonLd = {
<ImageWrapper src={entry.data.image} basePath={path.join("content/posts/", getDir(entry.id))} class="mb-8 rounded-xl banner-container onload-animation"/>
}

{entry.data.font == "USDeclaration" &&
<Markdown class="mb-6 markdown-content onload-animation font-USDeclaration">
<Content />
</Markdown>
}

{entry.data.font == "Ubuntu" &&
<Markdown class="mb-6 markdown-content onload-animation font-Ubuntu">
<Content />
</Markdown>
}

<Markdown class="mb-6 markdown-content onload-animation">
<Content />
</Markdown>
{entry.data.font == null &&
<Markdown class="mb-6 markdown-content onload-animation font-Ubuntu">
<Content />
</Markdown>
}

{licenseConfig.enable && <License title={entry.data.title} slug={entry.slug} pubDate={entry.data.published} class="mb-6 rounded-xl license-container onload-animation"></License>}

Expand Down
4 changes: 3 additions & 1 deletion tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = {
theme: {
extend: {
fontFamily: {
sans: ["Roboto", "sans-serif", ...defaultTheme.fontFamily.sans],
sans: ["Ubuntu", "sans-serif", ...defaultTheme.fontFamily.sans],
Ubuntu: ["Ubuntu", "sans-serif", ...defaultTheme.fontFamily.sans],
USDeclaration: ["USDeclaration", "sans-serif", ...defaultTheme.fontFamily.sans],
},
},
},
Expand Down

0 comments on commit e0a9a5b

Please sign in to comment.