diff --git a/hindki/astro.config.mjs b/hindki/astro.config.mjs index 2688f8c..98af8a1 100644 --- a/hindki/astro.config.mjs +++ b/hindki/astro.config.mjs @@ -35,18 +35,6 @@ try { console.warn(" Sidebar will not include vocabulary tags"); } -const vocabList = [ - { - label: "Index", - link: `/vocabulary`, - }, -].concat( - tagsList.map((tag) => ({ - label: tag.name.charAt(0).toUpperCase() + tag.name.slice(1), - link: `/vocabulary/${tag.name}`, - })), -); - // https://astro.build/config export default defineConfig({ vite: { @@ -79,7 +67,7 @@ export default defineConfig({ }, { label: "Vocabulary", - items: vocabList, + items: [], // Replace at runtime using API }, { label: "Culture", @@ -98,6 +86,10 @@ export default defineConfig({ label: "Learn", link: "/learn", }, + { + label: "Journal", + items: [], // Replace at runtime using getCollection + }, ], components: { Sidebar: "@/components/Sidebar.astro", diff --git a/hindki/src/components/Sidebar.astro b/hindki/src/components/Sidebar.astro index e5addd2..a7f7cc3 100644 --- a/hindki/src/components/Sidebar.astro +++ b/hindki/src/components/Sidebar.astro @@ -5,7 +5,8 @@ import SidebarSublist from "@astrojs/starlight/components/SidebarSublist.astro"; // @ts-ignore import MobileMenuFooter from "virtual:starlight/components/MobileMenuFooter"; import { storage } from "../lib/storage"; -import { titlecase } from "@/lib/utils"; +import { dateToTitle, titlecase } from "@/lib/utils"; +import { getCollection } from "astro:content"; const tags = await storage.getPageTags(); @@ -24,11 +25,32 @@ const tagsFromApi = { })), }; +const journalEntries = await getCollection("journal").then((entries) => { + return { + type: "group" as const, + label: "Journal", + badge: undefined, + entries: entries + .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) + .map((entry) => ({ + type: "link" as const, + label: dateToTitle(entry.id), + href: `/journal/${entry.id}`, + isCurrent: Astro.url.pathname === `/journal/${entry.id}`, + badge: undefined, + attrs: {}, + })), + }; +}); + // Replace vocabulary with tags fetched from api const sidebar = astroSidebar.map((item: any) => { if (item.label === "Vocabulary") { return tagsFromApi; } + if (item.label === "Journal") { + return journalEntries; + } return item; }); --- diff --git a/hindki/src/content.config.ts b/hindki/src/content.config.ts index 7fbcf2c..c8ff650 100644 --- a/hindki/src/content.config.ts +++ b/hindki/src/content.config.ts @@ -1,7 +1,14 @@ import { defineCollection } from "astro:content"; import { docsLoader } from "@astrojs/starlight/loaders"; import { docsSchema } from "@astrojs/starlight/schema"; +import { glob } from "astro/loaders"; export const collections = { docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), + journal: defineCollection({ + loader: glob({ + base: "src/content/journal", + pattern: "**/*.(md|mdx)", + }) + }) }; diff --git a/hindki/src/content/journal/2025-10-16.mdx b/hindki/src/content/journal/2025-10-16.mdx new file mode 100644 index 0000000..26ac188 --- /dev/null +++ b/hindki/src/content/journal/2025-10-16.mdx @@ -0,0 +1,46 @@ +आज मेरी हिंदी की कक्षा था. + +हमने आखिरी chapter पढ़ी पहली किताब से ("Introduction to Hindi Grammar"). + +नीचे देखेंगे मैंने क्या-क्या लिखी तैयार करने में. + +## मेरा पिछला हफ़्ता + +मेरा हफ्ता दिलचस्प था, बहुत हुआ. + +पिछले शुक्रवार, एक conference गया stanford में जिसमें मैने भाषण दी अपने समय के बारे में जब company बना रहा था। + +बाद में, आदमी से मिला जो काम करता है वहीं company में की अब मैं apply कर रहा हूं। सोचता हूँ कि उसे पसंद हूं, देखेंगे। + +यह चीज palo alto में थी, और सुबह सुबह शुरू हुई, इसलिए मैं और मेरी बीवी ने होटल ली, "staycation" के जैसे। + +शनिवार को मैने उसे दिखाया मेरा पसंदीदा भोजनालय जिसमें पकता है caribbean jerk tofu, बहुत अच्छा है। मसालेदार। + +फिर वापस आकर कुछ दोस्तों से मिले रात के खाने के लिए। + +कल, मैने देखी bollywood फिल्म नाम का "कल हो ना हो", दूसरी शाह रुख खान वाली फिल्म। कुछ 2000s cringe के अलावा, अच्छी लगी मुझे + +--- + +Today I had a Hindi class. + +We studied the last chapter in the first book ("Introduction to Hindi Grammar"). + +Below you'll see what I prepared for the class today. + +## My past week + +My week was interesting, a lot happened. + +Last Friday I was at an event for work where I spoke on a panel about my time making a company. + +After, i met someone who works at the company I'm now trying to join. + +I think he liked me, we will see. + +This event was in Palo Alto and started early Friday morning, so we did a staycation and my wife joined me after work, and we spent Saturday in Palo Alto as well. I showed her my favorite Caribbean restaurant that makes jerk tofu. + +Then we saw some friends who recently moved back to California from New York. + +Finally, I saw a Bollywood film yesterday, "Kal Ho Naa Ho", another Shah Rukh Khan film. I liked it. Other than some 2000s cringe, it was good. + diff --git a/hindki/src/lib/utils.ts b/hindki/src/lib/utils.ts index 22ca9f2..ac9b05b 100644 --- a/hindki/src/lib/utils.ts +++ b/hindki/src/lib/utils.ts @@ -12,3 +12,11 @@ export function typeToTitle(type: string | null | undefined) { const maybePlural = partsOfSpeech.includes(type.toLowerCase()) ? "s" : ""; return titlecase(type!) + maybePlural; } + +export function dateToTitle(dateStr: string) { + const date = new Date(dateStr + 'T00:00:00Z'); // Parse as UTC + if (isNaN(date.getTime())) return dateStr; // Invalid date, return as is + + const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }; + return date.toLocaleDateString('en-US', options); +} \ No newline at end of file diff --git a/hindki/src/pages/journal/[date].astro b/hindki/src/pages/journal/[date].astro new file mode 100644 index 0000000..dad7afd --- /dev/null +++ b/hindki/src/pages/journal/[date].astro @@ -0,0 +1,53 @@ +--- +import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"; +import AnchorHeading from "@astrojs/starlight/components/AnchorHeading.astro"; +import markdownit from "markdown-it"; +import markdownItMark from "markdown-it-mark"; +import { titlecase, dateToTitle } from "@/lib/utils"; +import { getCollection } from "astro:content"; +import { render, renderInline, highlight } from "@/lib/markdown"; +import { Tabs, TabItem } from "@astrojs/starlight/components"; + +export async function getStaticPaths() { + const allEntries = await getCollection("journal"); + console.log(allEntries); + return allEntries.map((entry) => ({ + params: { date: entry.id }, + })); +} +export const prerender = true; + +const md = markdownit().use(markdownItMark); +const { date } = Astro.params; + +if (!date) { + return Astro.redirect("/journal"); +} + +const allEntries = await getCollection("journal"); +const currentEntry = allEntries.find((entry) => entry.id === date); + +if (!currentEntry) { + return Astro.redirect("/journal"); +} + +const parts = currentEntry.body!.split("\n\n---\n\n"); +--- + + + { + parts.length > 1 && ( + + +
+ + +
+ + + ) + } + {parts.length == 1 &&
} +