astro-awesomeness 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.js.map +1 -1
- package/dist/content/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/{lib-C9WpNvm3.js → lib-CBjp3x7a.js} +5 -5
- package/dist/lib-CBjp3x7a.js.map +1 -0
- package/dist/styles/globals.css +1 -0
- package/package.json +6 -6
- package/src/components/theme-toggle.tsx +0 -6
- package/src/components/ui/button.tsx +0 -1
- package/src/content/index.ts +0 -4
- package/src/layouts/base-layout.astro +0 -3
- package/src/lib/format-date.ts +0 -2
- package/src/lib/post-url.ts +0 -20
- package/src/lib/require-env.ts +0 -3
- package/src/lib/tag-url.ts +0 -3
- package/src/styles/globals.css +1 -0
- package/dist/lib-C9WpNvm3.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ButtonPrimitive"],"sources":["../../src/components/ui/button-variants.ts","../../src/components/ui/button.tsx","../../src/components/theme-toggle.tsx"],"sourcesContent":["import { cva } from \"class-variance-authority\";\n\nconst buttonVariants = cva(\n \"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n {\n defaultVariants: {\n size: \"default\",\n variant: \"default\",\n },\n variants: {\n size: {\n default: \"h-9 px-4 py-2 has-[>svg]:px-3\",\n icon: \"size-9\",\n \"icon-lg\": \"size-10\",\n \"icon-sm\": \"size-8\",\n \"icon-xs\": \"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3\",\n lg: \"h-10 rounded-md px-6 has-[>svg]:px-4\",\n sm: \"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5\",\n xs: \"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3\",\n },\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive:\n \"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40\",\n ghost: \"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50\",\n link: \"text-primary underline-offset-4 hover:underline\",\n outline:\n \"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n },\n },\n },\n);\n\nexport { buttonVariants };\n","import { Button as ButtonPrimitive } from \"@base-ui/react/button\";\nimport type { VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { cn } from \"../../lib/cn\";\nimport { buttonVariants } from \"./button-variants\";\n\ntype ButtonProps = Omit<React.ComponentProps<typeof ButtonPrimitive>, \"className\"> &\n VariantProps<typeof buttonVariants> & {\n className?: string;\n };\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":["ButtonPrimitive"],"sources":["../../src/components/ui/button-variants.ts","../../src/components/ui/button.tsx","../../src/components/theme-toggle.tsx"],"sourcesContent":["import { cva } from \"class-variance-authority\";\n\nconst buttonVariants = cva(\n \"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n {\n defaultVariants: {\n size: \"default\",\n variant: \"default\",\n },\n variants: {\n size: {\n default: \"h-9 px-4 py-2 has-[>svg]:px-3\",\n icon: \"size-9\",\n \"icon-lg\": \"size-10\",\n \"icon-sm\": \"size-8\",\n \"icon-xs\": \"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3\",\n lg: \"h-10 rounded-md px-6 has-[>svg]:px-4\",\n sm: \"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5\",\n xs: \"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3\",\n },\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive:\n \"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40\",\n ghost: \"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50\",\n link: \"text-primary underline-offset-4 hover:underline\",\n outline:\n \"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n },\n },\n },\n);\n\nexport { buttonVariants };\n","import { Button as ButtonPrimitive } from \"@base-ui/react/button\";\nimport type { VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { cn } from \"../../lib/cn\";\nimport { buttonVariants } from \"./button-variants\";\n\ntype ButtonProps = Omit<React.ComponentProps<typeof ButtonPrimitive>, \"className\"> &\n VariantProps<typeof buttonVariants> & {\n className?: string;\n };\n\nconst Button = ({ className, size = \"default\", variant = \"default\", ...props }: ButtonProps) => {\n return (\n <ButtonPrimitive\n className={cn(buttonVariants({ className, size, variant }))}\n data-size={size}\n data-slot=\"button\"\n data-variant={variant}\n {...props}\n />\n );\n};\n\nexport { Button };\n","import { Moon, Sun } from \"lucide-react\";\nimport { useSyncExternalStore } from \"react\";\n\nimport { Button } from \"./ui/button\";\n\ntype Theme = \"light\" | \"dark\";\n\nconst getStoredTheme = (): Theme | null => {\n if (typeof window === \"undefined\") {\n return null;\n }\n const stored = window.localStorage.getItem(\"theme\");\n if (stored === \"light\" || stored === \"dark\") {\n return stored;\n }\n return null;\n};\n\nconst storedThemeListeners = new Set<() => void>();\n\nconst subscribeStoredTheme = (callback: () => void) => {\n if (typeof window === \"undefined\") {\n return () => {};\n }\n storedThemeListeners.add(callback);\n window.addEventListener(\"storage\", callback);\n return () => {\n storedThemeListeners.delete(callback);\n window.removeEventListener(\"storage\", callback);\n };\n};\n\nconst setStoredTheme = (next: Theme) => {\n window.localStorage.setItem(\"theme\", next);\n for (const listener of storedThemeListeners) {\n listener();\n }\n};\n\nconst getPrefersDark = (): boolean => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches;\n};\n\nconst subscribePrefersDark = (callback: () => void) => {\n if (typeof window === \"undefined\") {\n return () => {};\n }\n const media = window.matchMedia(\"(prefers-color-scheme: dark)\");\n media.addEventListener(\"change\", callback);\n return () => {\n media.removeEventListener(\"change\", callback);\n };\n};\n\ntype Props = {\n ariaLabel?: string;\n};\n\nconst ThemeToggle = ({ ariaLabel = \"Toggle theme\" }: Props) => {\n const prefersDark = useSyncExternalStore(subscribePrefersDark, getPrefersDark, () => false);\n const override = useSyncExternalStore(subscribeStoredTheme, getStoredTheme, () => null);\n const theme: Theme = override ?? (prefersDark ? \"dark\" : \"light\");\n\n const handleToggleTheme = () => {\n const next: Theme = theme === \"dark\" ? \"light\" : \"dark\";\n document.documentElement.classList.toggle(\"dark\", next === \"dark\");\n setStoredTheme(next);\n };\n\n return (\n <Button aria-label={ariaLabel} onClick={handleToggleTheme} size=\"icon\" variant=\"ghost\">\n {theme === \"dark\" ? <Sun /> : <Moon />}\n </Button>\n );\n};\n\nexport { ThemeToggle };\n"],"mappings":";;;;;;;;AAEA,MAAM,iBAAiB,IACrB,+bACA;CACE,iBAAiB;EACf,MAAM;EACN,SAAS;CACX;CACA,UAAU;EACR,MAAM;GACJ,SAAS;GACT,MAAM;GACN,WA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qBAA4B;CAC7D,MAAM,cAAc,qBAAqB,sBAAsB,sBAAsB,KAAK;CAE1F,MAAM,QADW,qBAAqB,sBAAsB,sBAAsB,IACtD,MAAM,cAAc,SAAS;CAEzD,MAAM,0BAA0B;EAC9B,MAAM,OAAc,UAAU,SAAS,UAAU;EACjD,SAAS,gBAAgB,UAAU,OAAO,QAAQ,SAAS,MAAM;EACjE,eAAe,IAAI;CACrB;CAEA,OACE,oBAAC,QAAD;EAAQ,cAAY;EAAW,SAAS;EAAmB,MAAK;EAAO,SAAQ;YAC5E,UAAU,SAAS,oBAAC,KAAD,CAAM,KAAI,oBAAC,MAAD,CAAO;CAC/B;AAEZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/content/index.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst postSchema = z.object({\n author: z.string().optional(),\n categories: z.array(z.string()).default([]),\n cover: z.string().optional(),\n coverAlt: z.string().optional(),\n description: z.string().default(\"\"),\n draft: z.boolean().default(false),\n heroImageHeight: z.number().int().optional(),\n heroImageUrl: z.url().optional(),\n heroImageWidth: z.number().int().optional(),\n pubDate: z.coerce.date(),\n seo: z\n .object({\n canonical_url: z.string().optional(),\n })\n .optional(),\n series: z.string().optional(),\n slug: z.string().optional(),\n status: z.string().optional(),\n tags: z.array(z.string()).default([]),\n title: z.string().min(1),\n updatedDate: z.coerce.date().optional(),\n});\n\nconst tagSchema = z.object({\n description: z.string().optional(),\n name: z.string().min(1),\n});\n\nconst authorSchema = z.object({\n avatar: z.string().optional(),\n bio: z.string().optional(),\n name: z.string().min(1),\n url: z.url().optional(),\n});\n\ntype Post = z.infer<typeof postSchema>;\ntype Tag = z.infer<typeof tagSchema>;\ntype Author = z.infer<typeof authorSchema>;\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/content/index.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst postSchema = z.object({\n author: z.string().optional(),\n categories: z.array(z.string()).default([]),\n cover: z.string().optional(),\n coverAlt: z.string().optional(),\n description: z.string().default(\"\"),\n draft: z.boolean().default(false),\n heroImageHeight: z.number().int().optional(),\n heroImageUrl: z.url().optional(),\n heroImageWidth: z.number().int().optional(),\n pubDate: z.coerce.date(),\n seo: z\n .object({\n canonical_url: z.string().optional(),\n })\n .optional(),\n series: z.string().optional(),\n slug: z.string().optional(),\n status: z.string().optional(),\n tags: z.array(z.string()).default([]),\n title: z.string().min(1),\n updatedDate: z.coerce.date().optional(),\n});\n\nconst tagSchema = z.object({\n description: z.string().optional(),\n name: z.string().min(1),\n});\n\nconst authorSchema = z.object({\n avatar: z.string().optional(),\n bio: z.string().optional(),\n name: z.string().min(1),\n url: z.url().optional(),\n});\n\ntype Post = z.infer<typeof postSchema>;\ntype Tag = z.infer<typeof tagSchema>;\ntype Author = z.infer<typeof authorSchema>;\n\nconst notDraft = (post: { data: { draft?: boolean; status?: string } }): boolean =>\n post.data.status !== \"DRAFT\" && post.data.draft !== true;\n\nconst byPubDateDesc = (a: { data: { pubDate: Date } }, b: { data: { pubDate: Date } }): number =>\n b.data.pubDate.valueOf() - a.data.pubDate.valueOf();\n\nexport { authorSchema, byPubDateDesc, notDraft, postSchema, tagSchema };\nexport type { Author, Post, Tag };\n"],"mappings":";;;;;;;;;;;AAEA,MAAM,aAAa,EAAE,OAAO;CAC1B,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CAC1C,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS;CAC9B,aAAa,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE;CAClC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,KAAK;CAChC,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;CAC3C,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS;CAC/B,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;CAC1C,SAAS,EAAE,OAAO,KAAK;CACvB,KAAK,EACF,OAAO,EACN,eAAe,EAAE,OAAO,CAAC,CAAC,SAAS,EACrC,CAAC,CAAC,CACD,SAAS;CACZ,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CACpC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACvB,aAAa,EAAE,OAAO,KAAK,CAAC,CAAC,SAAS;AACxC,CAAC;AAED,MAAM,YAAY,EAAE,OAAO;CACzB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;CACjC,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AACxB,CAAC;AAED,MAAM,eAAe,EAAE,OAAO;CAC5B,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,KAAK,EAAE,OAAO,CAAC,CAAC,SAAS;CACzB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACtB,KAAK,EAAE,IAAI,CAAC,CAAC,SAAS;AACxB,CAAC;AAMD,MAAM,YAAY,SAChB,KAAK,KAAK,WAAW,WAAW,KAAK,KAAK,UAAU;AAEtD,MAAM,iBAAiB,GAAgC,MACrD,EAAE,KAAK,QAAQ,QAAQ,IAAI,EAAE,KAAK,QAAQ,QAAQ"}
|
package/dist/index.js
CHANGED
package/dist/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { t as cn } from "../cn-DmzdyV07.js";
|
|
2
|
-
import { a as readingTime, c as slugify, i as requireEnv, l as getRelatedPosts, n as DEFAULT_TAG_BASE, o as categoryLabel, r as tagUrl, s as createPostUrl, u as formatDate } from "../lib-
|
|
2
|
+
import { a as readingTime, c as slugify, i as requireEnv, l as getRelatedPosts, n as DEFAULT_TAG_BASE, o as categoryLabel, r as tagUrl, s as createPostUrl, u as formatDate } from "../lib-CBjp3x7a.js";
|
|
3
3
|
|
|
4
4
|
export { DEFAULT_TAG_BASE, categoryLabel, cn, createPostUrl, formatDate, getRelatedPosts, readingTime, requireEnv, slugify, tagUrl };
|
|
@@ -45,7 +45,7 @@ const getRelatedPosts = (current, all, n) => {
|
|
|
45
45
|
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/lib/slugify.ts
|
|
48
|
-
const slugify = (input) => input.normalize("NFD").replaceAll(
|
|
48
|
+
const slugify = (input) => input.normalize("NFD").replaceAll(new RegExp("[̀-ͯ]", "gv"), "").toLowerCase().replaceAll(new RegExp("[^a-z0-9\\s\\-]", "gv"), "").trim().replaceAll(new RegExp("[\\s\\-]+", "gv"), "-").replaceAll(new RegExp("^-+|-+$", "gv"), "");
|
|
49
49
|
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region src/lib/post-url.ts
|
|
@@ -93,7 +93,7 @@ const NAMED_ENTITIES = {
|
|
|
93
93
|
const MAX_CODE_POINT = 1114111;
|
|
94
94
|
const EM_DASH = 8212;
|
|
95
95
|
const HEX_RADIX = 16;
|
|
96
|
-
const ENTITY_PATTERN =
|
|
96
|
+
const ENTITY_PATTERN = new RegExp("&(?:#(?<decimal>\\d+)|#x(?<hex>[\\dA-F]+)|(?<named>[A-Z]+));", "giv");
|
|
97
97
|
const fromCodePoint = (codePoint, entity) => Number.isInteger(codePoint) && codePoint <= MAX_CODE_POINT && codePoint !== EM_DASH ? String.fromCodePoint(codePoint) : entity;
|
|
98
98
|
const decodeEntity = (entity, decimal, hex, named) => {
|
|
99
99
|
if (decimal !== void 0) return fromCodePoint(Number(decimal), entity);
|
|
@@ -108,7 +108,7 @@ const categoryLabel = (name) => name.replaceAll(ENTITY_PATTERN, decodeEntity);
|
|
|
108
108
|
//#region src/lib/reading-time.ts
|
|
109
109
|
const WORDS_PER_MINUTE = 200;
|
|
110
110
|
const readingTime = (input) => {
|
|
111
|
-
const stripped = input.replaceAll(
|
|
111
|
+
const stripped = input.replaceAll(new RegExp("<[^>]*>", "gv"), "").replaceAll(new RegExp("[#*_`>\\-]", "gv"), " ").replaceAll(new RegExp("\\s+", "gv"), " ").trim();
|
|
112
112
|
const words = stripped.length === 0 ? 0 : stripped.split(" ").length;
|
|
113
113
|
return {
|
|
114
114
|
minutes: Math.max(1, Math.ceil(words / WORDS_PER_MINUTE)),
|
|
@@ -127,7 +127,7 @@ const requireEnv = (name) => {
|
|
|
127
127
|
//#endregion
|
|
128
128
|
//#region src/lib/tag-url.ts
|
|
129
129
|
const DEFAULT_TAG_BASE = "/tag";
|
|
130
|
-
const tagUrl = (tag, base = DEFAULT_TAG_BASE) => `${base.replace(
|
|
130
|
+
const tagUrl = (tag, base = DEFAULT_TAG_BASE) => `${base.replace(new RegExp("\\/+$", "v"), "")}/${slugify(tag)}/`;
|
|
131
131
|
|
|
132
132
|
//#endregion
|
|
133
133
|
//#region src/lib/index.ts
|
|
@@ -146,4 +146,4 @@ var lib_exports = /* @__PURE__ */ __exportAll({
|
|
|
146
146
|
|
|
147
147
|
//#endregion
|
|
148
148
|
export { readingTime as a, slugify as c, requireEnv as i, getRelatedPosts as l, DEFAULT_TAG_BASE as n, categoryLabel as o, tagUrl as r, createPostUrl as s, lib_exports as t, formatDate as u };
|
|
149
|
-
//# sourceMappingURL=lib-
|
|
149
|
+
//# sourceMappingURL=lib-CBjp3x7a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib-CBjp3x7a.js","names":[],"sources":["../src/lib/format-date.ts","../src/lib/get-related-posts.ts","../src/lib/slugify.ts","../src/lib/post-url.ts","../src/lib/reading-time.ts","../src/lib/require-env.ts","../src/lib/tag-url.ts","../src/lib/index.ts"],"sourcesContent":["const defaultOptions: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"long\",\n timeZone: \"UTC\",\n year: \"numeric\",\n};\n\nconst formatterCache = new Map<string, Intl.DateTimeFormat>();\n\nconst getFormatter = (key: string, locale: string, options: Intl.DateTimeFormatOptions) => {\n let formatter = formatterCache.get(key);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, options);\n formatterCache.set(key, formatter);\n }\n return formatter;\n};\n\nconst formatDate = (date: Date, locale: string = \"en-US\", options?: Intl.DateTimeFormatOptions) => {\n if (!options) {\n return getFormatter(locale, locale, defaultOptions).format(date);\n }\n const merged = { ...defaultOptions, ...options };\n return getFormatter(`${locale}:${JSON.stringify(merged)}`, locale, merged).format(date);\n};\n\nexport { formatDate };\n","type HasTags = { data: { tags: Array<string> }; id: string };\n\nconst getRelatedPosts = <T extends HasTags>(current: T, all: Array<T>, n: number) => {\n const currentTagSet = new Set(current.data.tags);\n const scored: Array<{ post: T; score: number }> = [];\n\n for (const post of all) {\n if (post.id === current.id) {\n continue;\n }\n let score = 0;\n for (const tag of post.data.tags) {\n if (currentTagSet.has(tag)) {\n score++;\n }\n }\n scored.push({ post, score });\n }\n\n return scored\n .toSorted((x, y) => y.score - x.score)\n .slice(0, n)\n .map(({ post }) => post);\n};\n\nexport { getRelatedPosts };\n","const slugify = (input: string) =>\n input\n .normalize(\"NFD\")\n .replaceAll(/[̀-ͯ]/gv, \"\")\n .toLowerCase()\n .replaceAll(/[^a-z0-9\\s\\-]/gv, \"\")\n .trim()\n .replaceAll(/[\\s\\-]+/gv, \"-\")\n .replaceAll(/^-+|-+$/gv, \"\");\n\nexport { slugify };\n","import { slugify } from \"./slugify\";\n\ntype PostLike = {\n data: {\n categories?: Array<string>;\n seo?: { canonical_url?: string };\n };\n id: string;\n};\n\ntype PostParams = { category: string; slug: string };\n\ntype PostUrlBuilder = {\n postParams: (post: PostLike) => PostParams;\n postUrl: (post: PostLike) => string;\n};\n\nconst createPostUrl = (\n categorySlugMap: Record<string, string>,\n defaultCategory: string,\n): PostUrlBuilder => {\n const postParams = (post: PostLike): PostParams => {\n const canonical = post.data.seo?.canonical_url;\n if (canonical !== undefined && canonical !== \"\") {\n try {\n const segments = new URL(canonical).pathname.split(\"/\").filter(Boolean);\n const category = segments.at(-2);\n const slug = segments.at(-1);\n if (category !== undefined && slug !== undefined) {\n return { category, slug };\n }\n } catch {\n // Malformed canonical_url; fall through to category-derived logic.\n }\n }\n const first = post.data.categories?.at(0);\n const category =\n first !== undefined && first !== \"\"\n ? (categorySlugMap[first] ?? slugify(first))\n : defaultCategory;\n return { category, slug: post.id };\n };\n\n const postUrl = (post: PostLike): string => {\n const { category, slug } = postParams(post);\n return `/${category}/${slug}/`;\n };\n\n return { postParams, postUrl };\n};\n\nconst NAMED_ENTITIES: Record<string, string> = {\n amp: \"&\",\n apos: \"'\",\n gt: \">\",\n hellip: \"\\u2026\",\n ldquo: \"\\u201c\",\n lsquo: \"\\u2018\",\n lt: \"<\",\n nbsp: \"\\u00a0\",\n ndash: \"\\u2013\",\n quot: '\"',\n rdquo: \"\\u201d\",\n rsquo: \"\\u2019\",\n};\n\nconst MAX_CODE_POINT = 1_114_111;\nconst EM_DASH = 8212;\nconst HEX_RADIX = 16;\nconst ENTITY_PATTERN = /&(?:#(?<decimal>\\d+)|#x(?<hex>[\\dA-F]+)|(?<named>[A-Z]+));/giv;\n\nconst fromCodePoint = (codePoint: number, entity: string): string =>\n Number.isInteger(codePoint) && codePoint <= MAX_CODE_POINT && codePoint !== EM_DASH\n ? String.fromCodePoint(codePoint)\n : entity;\n\nconst decodeEntity = (entity: string, decimal?: string, hex?: string, named?: string): string => {\n if (decimal !== undefined) {\n return fromCodePoint(Number(decimal), entity);\n }\n if (hex !== undefined) {\n return fromCodePoint(Number.parseInt(hex, HEX_RADIX), entity);\n }\n if (named === undefined) {\n return entity;\n }\n const key = named.toLowerCase();\n return Object.hasOwn(NAMED_ENTITIES, key) ? (NAMED_ENTITIES[key] ?? entity) : entity;\n};\n\nconst categoryLabel = (name: string): string => name.replaceAll(ENTITY_PATTERN, decodeEntity);\n\nexport type { PostLike, PostParams, PostUrlBuilder };\nexport { categoryLabel, createPostUrl };\n","const WORDS_PER_MINUTE = 200;\n\nconst readingTime = (input: string) => {\n const stripped = input\n .replaceAll(/<[^>]*>/gv, \"\")\n .replaceAll(/[#*_`>\\-]/gv, \" \")\n .replaceAll(/\\s+/gv, \" \")\n .trim();\n const words = stripped.length === 0 ? 0 : stripped.split(\" \").length;\n const minutes = Math.max(1, Math.ceil(words / WORDS_PER_MINUTE));\n return { minutes, words };\n};\n\nexport { readingTime };\n","const requireEnv = (name: string): string => {\n const value = process.env[name];\n if (value === undefined || value === \"\") {\n throw new Error(`Missing required env var: ${name}`);\n }\n return value;\n};\n\nexport { requireEnv };\n","import { slugify } from \"./slugify\";\n\nconst DEFAULT_TAG_BASE = \"/tag\";\n\nconst tagUrl = (tag: string, base: string = DEFAULT_TAG_BASE): string =>\n `${base.replace(/\\/+$/v, \"\")}/${slugify(tag)}/`;\n\nexport { DEFAULT_TAG_BASE, tagUrl };\n","export { cn } from \"./cn\";\nexport { formatDate } from \"./format-date\";\nexport { getRelatedPosts } from \"./get-related-posts\";\nexport type { PostLike, PostParams, PostUrlBuilder } from \"./post-url\";\nexport { categoryLabel, createPostUrl } from \"./post-url\";\nexport { readingTime } from \"./reading-time\";\nexport { requireEnv } from \"./require-env\";\nexport { slugify } from \"./slugify\";\nexport { DEFAULT_TAG_BASE, tagUrl } from \"./tag-url\";\n"],"mappings":";;;;AAAA,MAAM,iBAA6C;CACjD,KAAK;CACL,OAAO;CACP,UAAU;CACV,MAAM;AACR;AAEA,MAAM,iCAAiB,IAAI,IAAiC;AAE5D,MAAM,gBAAgB,KAAa,QAAgB,YAAwC;CACzF,IAAI,YAAY,eAAe,IAAI,GAAG;CACtC,IAAI,CAAC,WAAW;EACd,YAAY,IAAI,KAAK,eAAe,QAAQ,OAAO;EACnD,eAAe,IAAI,KAAK,SAAS;CACnC;CACA,OAAO;AACT;AAEA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AW,MACd,WAAW,0BAAU,GAAG,EAAE,CAAC,CAC3B,WAAW,6BAAY,GAAG,GAAG,CAAC,CAC9B,WAAW,uBAAM,GAAG,GAAG,CAAC,CACxB,KAAK;CACR,MAAM,QAAQ,SAAS,WAAW,IAAI,IAAI,SAAS,MAAM,GAAG,CAAC,CAAC;CAE9D,OAAO;EAAE,SADO,KAAK,IAAI,GAAG,KAAK,KAAK,QAAQ,gBAAgB,CAC/C;EAAG;CAAM;AAC1B;;;;ACXA,MAAM,cAAc,SAAyB;CAC3C,MAAM,QAAQ,QAAQ,IAAI;CAC1B,IAAI,UAAU,UAAa,UAAU,IACnC,MAAM,IAAI,MAAM,6BAA6B,MAAM;CAErD,OAAO;AACT;;;;ACJA,MAAM,mBAAmB;AAEzB,MAAM,UAAU,KAAa,OAAe,qBAC1C,GAAG,KAAK,QAAQ,uBAAM,GAAG,EAAE,EAAE,GAAG,QAAQ,GAAG,EAAE"}
|
package/dist/styles/globals.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-awesomeness",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Astro 6/7 blog theme with shadcn primitives and a Tailwind v4 preset.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -54,22 +54,22 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@base-ui/react": "^1.6.0",
|
|
56
56
|
"class-variance-authority": "^0.7.1",
|
|
57
|
-
"cnfast": "^0.0
|
|
58
|
-
"lucide-react": "^1.
|
|
57
|
+
"cnfast": "^0.1.0",
|
|
58
|
+
"lucide-react": "^1.31.0",
|
|
59
59
|
"tw-animate-css": "^1.4.0",
|
|
60
60
|
"zod": "^4.4.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@tailwindcss/postcss": "^4.3.2",
|
|
64
|
-
"@types/node": "^26.
|
|
64
|
+
"@types/node": "^26.2.0",
|
|
65
65
|
"@types/react": "^19.2.17",
|
|
66
66
|
"@types/react-dom": "^19.2.3",
|
|
67
67
|
"@vitest/coverage-v8": "^4.1.10",
|
|
68
68
|
"tailwindcss": "^4.3.2",
|
|
69
69
|
"typescript": "^6.0.3",
|
|
70
70
|
"vitest": "^4.1.10",
|
|
71
|
-
"@repo/config
|
|
72
|
-
"@repo/
|
|
71
|
+
"@repo/typescript-config": "0.0.0",
|
|
72
|
+
"@repo/config-vitest": "0.0.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"astro": "^6.0.0 || ^7.0.0",
|
|
@@ -23,7 +23,6 @@ const subscribeStoredTheme = (callback: () => void) => {
|
|
|
23
23
|
return () => {};
|
|
24
24
|
}
|
|
25
25
|
storedThemeListeners.add(callback);
|
|
26
|
-
// "storage" only fires in other tabs; same-tab writes notify via setStoredTheme.
|
|
27
26
|
window.addEventListener("storage", callback);
|
|
28
27
|
return () => {
|
|
29
28
|
storedThemeListeners.delete(callback);
|
|
@@ -61,11 +60,6 @@ type Props = {
|
|
|
61
60
|
};
|
|
62
61
|
|
|
63
62
|
const ThemeToggle = ({ ariaLabel = "Toggle theme" }: Props) => {
|
|
64
|
-
// useSyncExternalStore avoids hydration mismatch on both reads: the server
|
|
65
|
-
// snapshots (false / null) match the server HTML, then React re-syncs to the
|
|
66
|
-
// real values right after hydration. Reading localStorage during the initial
|
|
67
|
-
// render instead (e.g. in a useState initializer) makes React 19 log a
|
|
68
|
-
// recoverable hydration error for every visitor with a stored theme.
|
|
69
63
|
const prefersDark = useSyncExternalStore(subscribePrefersDark, getPrefersDark, () => false);
|
|
70
64
|
const override = useSyncExternalStore(subscribeStoredTheme, getStoredTheme, () => null);
|
|
71
65
|
const theme: Theme = override ?? (prefersDark ? "dark" : "light");
|
|
@@ -10,7 +10,6 @@ type ButtonProps = Omit<React.ComponentProps<typeof ButtonPrimitive>, "className
|
|
|
10
10
|
className?: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
// React 19 passes `ref` as a regular prop, so no forwardRef wrapper is needed.
|
|
14
13
|
const Button = ({ className, size = "default", variant = "default", ...props }: ButtonProps) => {
|
|
15
14
|
return (
|
|
16
15
|
<ButtonPrimitive
|
package/src/content/index.ts
CHANGED
|
@@ -40,13 +40,9 @@ type Post = z.infer<typeof postSchema>;
|
|
|
40
40
|
type Tag = z.infer<typeof tagSchema>;
|
|
41
41
|
type Author = z.infer<typeof authorSchema>;
|
|
42
42
|
|
|
43
|
-
// One source of truth for the draft guard so the loader contract stays in sync
|
|
44
|
-
// with the consumer-side check (`data.status !== "DRAFT" && !data.draft`).
|
|
45
43
|
const notDraft = (post: { data: { draft?: boolean; status?: string } }): boolean =>
|
|
46
44
|
post.data.status !== "DRAFT" && post.data.draft !== true;
|
|
47
45
|
|
|
48
|
-
// Typed structurally instead of against `CollectionEntry` so this module never
|
|
49
|
-
// imports `astro:content`: that is a virtual module tsdown cannot resolve.
|
|
50
46
|
const byPubDateDesc = (a: { data: { pubDate: Date } }, b: { data: { pubDate: Date } }): number =>
|
|
51
47
|
b.data.pubDate.valueOf() - a.data.pubDate.valueOf();
|
|
52
48
|
|
|
@@ -33,9 +33,6 @@ const {
|
|
|
33
33
|
colorScheme = "auto",
|
|
34
34
|
} = Astro.props;
|
|
35
35
|
|
|
36
|
-
// Emitted through set:html rather than as literal script children so the two
|
|
37
|
-
// branches stay one <script> tag; Astro does not evaluate expressions inside
|
|
38
|
-
// script contents.
|
|
39
36
|
const colorSchemeScript = colorScheme === "auto"
|
|
40
37
|
? `(() => {
|
|
41
38
|
const stored = localStorage.getItem("theme");
|
package/src/lib/format-date.ts
CHANGED
|
@@ -17,8 +17,6 @@ const getFormatter = (key: string, locale: string, options: Intl.DateTimeFormatO
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const formatDate = (date: Date, locale: string = "en-US", options?: Intl.DateTimeFormatOptions) => {
|
|
20
|
-
// Default-option calls (every blog passes only (date, locale)) key on locale
|
|
21
|
-
// alone, skipping the JSON.stringify the custom-option path needs.
|
|
22
20
|
if (!options) {
|
|
23
21
|
return getFormatter(locale, locale, defaultOptions).format(date);
|
|
24
22
|
}
|
package/src/lib/post-url.ts
CHANGED
|
@@ -15,11 +15,6 @@ type PostUrlBuilder = {
|
|
|
15
15
|
postUrl: (post: PostLike) => string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
// Per-blog URL builder. Each blog supplies its own pt-BR -> slug map
|
|
19
|
-
// (`category-slugs.json`) and the catch-all category used when the post has
|
|
20
|
-
// no categories. The canonical_url short-circuit lets WordPress migrations
|
|
21
|
-
// keep their original URL pair while everything else falls back to a slugified
|
|
22
|
-
// derived category + Astro entry id.
|
|
23
18
|
const createPostUrl = (
|
|
24
19
|
categorySlugMap: Record<string, string>,
|
|
25
20
|
defaultCategory: string,
|
|
@@ -54,10 +49,6 @@ const createPostUrl = (
|
|
|
54
49
|
return { postParams, postUrl };
|
|
55
50
|
};
|
|
56
51
|
|
|
57
|
-
// Escapes rather than literal glyphs so nothing invisible or ambiguous sits in
|
|
58
|
-
// source. `mdash` is deliberately absent: U+2014 is banned across these blogs, so
|
|
59
|
-
// an encoded em-dash stays encoded rather than being decoded into a banned
|
|
60
|
-
// character.
|
|
61
52
|
const NAMED_ENTITIES: Record<string, string> = {
|
|
62
53
|
amp: "&",
|
|
63
54
|
apos: "'",
|
|
@@ -78,10 +69,6 @@ const EM_DASH = 8212;
|
|
|
78
69
|
const HEX_RADIX = 16;
|
|
79
70
|
const ENTITY_PATTERN = /&(?:#(?<decimal>\d+)|#x(?<hex>[\dA-F]+)|(?<named>[A-Z]+));/giv;
|
|
80
71
|
|
|
81
|
-
// `String.fromCodePoint` throws on anything past the Unicode range, which would
|
|
82
|
-
// take a whole static build down over one malformed entity. U+2014 is refused for
|
|
83
|
-
// the same reason `mdash` is absent above: a numeric escape must not become the
|
|
84
|
-
// way the banned glyph reaches a page.
|
|
85
72
|
const fromCodePoint = (codePoint: number, entity: string): string =>
|
|
86
73
|
Number.isInteger(codePoint) && codePoint <= MAX_CODE_POINT && codePoint !== EM_DASH
|
|
87
74
|
? String.fromCodePoint(codePoint)
|
|
@@ -97,17 +84,10 @@ const decodeEntity = (entity: string, decimal?: string, hex?: string, named?: st
|
|
|
97
84
|
if (named === undefined) {
|
|
98
85
|
return entity;
|
|
99
86
|
}
|
|
100
|
-
// Bare indexing would resolve `&constructor;` up the prototype chain and
|
|
101
|
-
// render `Function.prototype.toString` output into the page.
|
|
102
87
|
const key = named.toLowerCase();
|
|
103
88
|
return Object.hasOwn(NAMED_ENTITIES, key) ? (NAMED_ENTITIES[key] ?? entity) : entity;
|
|
104
89
|
};
|
|
105
90
|
|
|
106
|
-
// WordPress migrations stored category names HTML-encoded and the content API
|
|
107
|
-
// returns `post.data.categories` the same way, so both `category-slugs.json` keys
|
|
108
|
-
// and post frontmatter carry raw entities. Display-only on purpose: `createPostUrl`
|
|
109
|
-
// resolves a slug by the raw, still-encoded name, so a decoded name must never
|
|
110
|
-
// reach that lookup or every affected post URL moves.
|
|
111
91
|
const categoryLabel = (name: string): string => name.replaceAll(ENTITY_PATTERN, decodeEntity);
|
|
112
92
|
|
|
113
93
|
export type { PostLike, PostParams, PostUrlBuilder };
|
package/src/lib/require-env.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// An unset shell variable reaches a CI build as "" rather than undefined, so an
|
|
2
|
-
// empty value has to count as missing or the failure surfaces much later, inside
|
|
3
|
-
// the content loader's HTTP call.
|
|
4
1
|
const requireEnv = (name: string): string => {
|
|
5
2
|
const value = process.env[name];
|
|
6
3
|
if (value === undefined || value === "") {
|
package/src/lib/tag-url.ts
CHANGED
|
@@ -2,9 +2,6 @@ import { slugify } from "./slugify";
|
|
|
2
2
|
|
|
3
3
|
const DEFAULT_TAG_BASE = "/tag";
|
|
4
4
|
|
|
5
|
-
// The trailing slash is not cosmetic. @astrojs/sitemap emits directory-style
|
|
6
|
-
// URLs, so a chip pointing at /tag/foo names a URL that is absent from the
|
|
7
|
-
// sitemap and only reachable through a redirect.
|
|
8
5
|
const tagUrl = (tag: string, base: string = DEFAULT_TAG_BASE): string =>
|
|
9
6
|
`${base.replace(/\/+$/v, "")}/${slugify(tag)}/`;
|
|
10
7
|
|
package/src/styles/globals.css
CHANGED
package/dist/lib-C9WpNvm3.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib-C9WpNvm3.js","names":[],"sources":["../src/lib/format-date.ts","../src/lib/get-related-posts.ts","../src/lib/slugify.ts","../src/lib/post-url.ts","../src/lib/reading-time.ts","../src/lib/require-env.ts","../src/lib/tag-url.ts","../src/lib/index.ts"],"sourcesContent":["const defaultOptions: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"long\",\n timeZone: \"UTC\",\n year: \"numeric\",\n};\n\nconst formatterCache = new Map<string, Intl.DateTimeFormat>();\n\nconst getFormatter = (key: string, locale: string, options: Intl.DateTimeFormatOptions) => {\n let formatter = formatterCache.get(key);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, options);\n formatterCache.set(key, formatter);\n }\n return formatter;\n};\n\nconst formatDate = (date: Date, locale: string = \"en-US\", options?: Intl.DateTimeFormatOptions) => {\n // Default-option calls (every blog passes only (date, locale)) key on locale\n // alone, skipping the JSON.stringify the custom-option path needs.\n if (!options) {\n return getFormatter(locale, locale, defaultOptions).format(date);\n }\n const merged = { ...defaultOptions, ...options };\n return getFormatter(`${locale}:${JSON.stringify(merged)}`, locale, merged).format(date);\n};\n\nexport { formatDate };\n","type HasTags = { data: { tags: Array<string> }; id: string };\n\nconst getRelatedPosts = <T extends HasTags>(current: T, all: Array<T>, n: number) => {\n const currentTagSet = new Set(current.data.tags);\n const scored: Array<{ post: T; score: number }> = [];\n\n for (const post of all) {\n if (post.id === current.id) {\n continue;\n }\n let score = 0;\n for (const tag of post.data.tags) {\n if (currentTagSet.has(tag)) {\n score++;\n }\n }\n scored.push({ post, score });\n }\n\n return scored\n .toSorted((x, y) => y.score - x.score)\n .slice(0, n)\n .map(({ post }) => post);\n};\n\nexport { getRelatedPosts };\n","const slugify = (input: string) =>\n input\n .normalize(\"NFD\")\n .replaceAll(/[̀-ͯ]/gv, \"\")\n .toLowerCase()\n .replaceAll(/[^a-z0-9\\s\\-]/gv, \"\")\n .trim()\n .replaceAll(/[\\s\\-]+/gv, \"-\")\n .replaceAll(/^-+|-+$/gv, \"\");\n\nexport { slugify };\n","import { slugify } from \"./slugify\";\n\ntype PostLike = {\n data: {\n categories?: Array<string>;\n seo?: { canonical_url?: string };\n };\n id: string;\n};\n\ntype PostParams = { category: string; slug: string };\n\ntype PostUrlBuilder = {\n postParams: (post: PostLike) => PostParams;\n postUrl: (post: PostLike) => string;\n};\n\n// Per-blog URL builder. Each blog supplies its own pt-BR -> slug map\n// (`category-slugs.json`) and the catch-all category used when the post has\n// no categories. The canonical_url short-circuit lets WordPress migrations\n// keep their original URL pair while everything else falls back to a slugified\n// derived category + Astro entry id.\nconst createPostUrl = (\n categorySlugMap: Record<string, string>,\n defaultCategory: string,\n): PostUrlBuilder => {\n const postParams = (post: PostLike): PostParams => {\n const canonical = post.data.seo?.canonical_url;\n if (canonical !== undefined && canonical !== \"\") {\n try {\n const segments = new URL(canonical).pathname.split(\"/\").filter(Boolean);\n const category = segments.at(-2);\n const slug = segments.at(-1);\n if (category !== undefined && slug !== undefined) {\n return { category, slug };\n }\n } catch {\n // Malformed canonical_url; fall through to category-derived logic.\n }\n }\n const first = post.data.categories?.at(0);\n const category =\n first !== undefined && first !== \"\"\n ? (categorySlugMap[first] ?? slugify(first))\n : defaultCategory;\n return { category, slug: post.id };\n };\n\n const postUrl = (post: PostLike): string => {\n const { category, slug } = postParams(post);\n return `/${category}/${slug}/`;\n };\n\n return { postParams, postUrl };\n};\n\n// Escapes rather than literal glyphs so nothing invisible or ambiguous sits in\n// source. `mdash` is deliberately absent: U+2014 is banned across these blogs, so\n// an encoded em-dash stays encoded rather than being decoded into a banned\n// character.\nconst NAMED_ENTITIES: Record<string, string> = {\n amp: \"&\",\n apos: \"'\",\n gt: \">\",\n hellip: \"\\u2026\",\n ldquo: \"\\u201c\",\n lsquo: \"\\u2018\",\n lt: \"<\",\n nbsp: \"\\u00a0\",\n ndash: \"\\u2013\",\n quot: '\"',\n rdquo: \"\\u201d\",\n rsquo: \"\\u2019\",\n};\n\nconst MAX_CODE_POINT = 1_114_111;\nconst EM_DASH = 8212;\nconst HEX_RADIX = 16;\nconst ENTITY_PATTERN = /&(?:#(?<decimal>\\d+)|#x(?<hex>[\\dA-F]+)|(?<named>[A-Z]+));/giv;\n\n// `String.fromCodePoint` throws on anything past the Unicode range, which would\n// take a whole static build down over one malformed entity. U+2014 is refused for\n// the same reason `mdash` is absent above: a numeric escape must not become the\n// way the banned glyph reaches a page.\nconst fromCodePoint = (codePoint: number, entity: string): string =>\n Number.isInteger(codePoint) && codePoint <= MAX_CODE_POINT && codePoint !== EM_DASH\n ? String.fromCodePoint(codePoint)\n : entity;\n\nconst decodeEntity = (entity: string, decimal?: string, hex?: string, named?: string): string => {\n if (decimal !== undefined) {\n return fromCodePoint(Number(decimal), entity);\n }\n if (hex !== undefined) {\n return fromCodePoint(Number.parseInt(hex, HEX_RADIX), entity);\n }\n if (named === undefined) {\n return entity;\n }\n // Bare indexing would resolve `&constructor;` up the prototype chain and\n // render `Function.prototype.toString` output into the page.\n const key = named.toLowerCase();\n return Object.hasOwn(NAMED_ENTITIES, key) ? (NAMED_ENTITIES[key] ?? entity) : entity;\n};\n\n// WordPress migrations stored category names HTML-encoded and the content API\n// returns `post.data.categories` the same way, so both `category-slugs.json` keys\n// and post frontmatter carry raw entities. Display-only on purpose: `createPostUrl`\n// resolves a slug by the raw, still-encoded name, so a decoded name must never\n// reach that lookup or every affected post URL moves.\nconst categoryLabel = (name: string): string => name.replaceAll(ENTITY_PATTERN, decodeEntity);\n\nexport type { PostLike, PostParams, PostUrlBuilder };\nexport { categoryLabel, createPostUrl };\n","const WORDS_PER_MINUTE = 200;\n\nconst readingTime = (input: string) => {\n const stripped = input\n .replaceAll(/<[^>]*>/gv, \"\")\n .replaceAll(/[#*_`>\\-]/gv, \" \")\n .replaceAll(/\\s+/gv, \" \")\n .trim();\n const words = stripped.length === 0 ? 0 : stripped.split(\" \").length;\n const minutes = Math.max(1, Math.ceil(words / WORDS_PER_MINUTE));\n return { minutes, words };\n};\n\nexport { readingTime };\n","// An unset shell variable reaches a CI build as \"\" rather than undefined, so an\n// empty value has to count as missing or the failure surfaces much later, inside\n// the content loader's HTTP call.\nconst requireEnv = (name: string): string => {\n const value = process.env[name];\n if (value === undefined || value === \"\") {\n throw new Error(`Missing required env var: ${name}`);\n }\n return value;\n};\n\nexport { requireEnv };\n","import { slugify } from \"./slugify\";\n\nconst DEFAULT_TAG_BASE = \"/tag\";\n\n// The trailing slash is not cosmetic. @astrojs/sitemap emits directory-style\n// URLs, so a chip pointing at /tag/foo names a URL that is absent from the\n// sitemap and only reachable through a redirect.\nconst tagUrl = (tag: string, base: string = DEFAULT_TAG_BASE): string =>\n `${base.replace(/\\/+$/v, \"\")}/${slugify(tag)}/`;\n\nexport { DEFAULT_TAG_BASE, tagUrl };\n","export { cn } from \"./cn\";\nexport { formatDate } from \"./format-date\";\nexport { getRelatedPosts } from \"./get-related-posts\";\nexport type { PostLike, PostParams, PostUrlBuilder } from \"./post-url\";\nexport { categoryLabel, createPostUrl } from \"./post-url\";\nexport { readingTime } from \"./reading-time\";\nexport { requireEnv } from \"./require-env\";\nexport { slugify } from \"./slugify\";\nexport { DEFAULT_TAG_BASE, tagUrl } from \"./tag-url\";\n"],"mappings":";;;;AAAA,MAAM,iBAA6C;CACjD,KAAK;CACL,OAAO;CACP,UAAU;CACV,MAAM;AACR;AAEA,MAAM,iCAAiB,IAAI,IAAiC;AAE5D,MAAM,gBAAgB,KAAa,QAAgB,YAAwC;CACzF,IAAI,YAAY,eAAe,IAAI,GAAG;CACtC,IAAI,CAAC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