chore: consistent formatting (#47)

This commit is contained in:
Christian Pillsbury
2025-10-09 12:18:31 -07:00
committed by GitHub
parent 9c6eaef2aa
commit 9c5b29a15b
35 changed files with 193 additions and 180 deletions
+3 -7
View File
@@ -1,6 +1,7 @@
import { file } from 'astro/loaders';
import { defineCollection, reference, z } from 'astro:content';
import { simpleGit } from 'simple-git';
import { globWithParser } from './utils/globWithParser';
const git = simpleGit();
@@ -12,9 +13,7 @@ const git = simpleGit();
function extractDateFromFilename(id: string): Date {
const match = id.match(/^(\d{4})-(\d{2})-(\d{2})-/);
if (!match) {
throw new Error(
`Filename "${id}" must follow format: YYYY-MM-DD-slug.{md,mdx}`,
);
throw new Error(`Filename "${id}" must follow format: YYYY-MM-DD-slug.{md,mdx}`);
}
const [, year, month, day] = match;
@@ -59,10 +58,7 @@ const blog = defineCollection({
data: {
...entry.data,
pubDate,
...(updatedDate
&& updatedDate.getTime() !== pubDate.getTime()
? { updatedDate }
: {}),
...(updatedDate && updatedDate.getTime() !== pubDate.getTime() ? { updatedDate } : {}),
},
};
},
+1
View File
@@ -1,4 +1,5 @@
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import { SITE_DESCRIPTION, SITE_TITLE } from '@/consts';
+4 -11
View File
@@ -3,30 +3,23 @@ export const FRAMEWORK_STYLES = {
react: ['css', 'tailwind', 'styled-components'],
} as const;
export const SUPPORTED_FRAMEWORKS = Object.keys(
FRAMEWORK_STYLES,
) as (keyof typeof FRAMEWORK_STYLES)[];
export const SUPPORTED_FRAMEWORKS = Object.keys(FRAMEWORK_STYLES) as (keyof typeof FRAMEWORK_STYLES)[];
export type SupportedFramework = keyof typeof FRAMEWORK_STYLES;
export type SupportedStyle<F extends SupportedFramework>
= (typeof FRAMEWORK_STYLES)[F][number];
export type SupportedStyle<F extends SupportedFramework> = (typeof FRAMEWORK_STYLES)[F][number];
export type AnySupportedStyle = SupportedStyle<SupportedFramework>;
/**
* Get the available styles for a given framework
*/
export function getAvailableStyles<F extends SupportedFramework>(
framework: F,
): readonly SupportedStyle<F>[] {
export function getAvailableStyles<F extends SupportedFramework>(framework: F): readonly SupportedStyle<F>[] {
return FRAMEWORK_STYLES[framework];
}
/**
* Get the default style for a given framework (first available style)
*/
export function getDefaultStyle<F extends SupportedFramework>(
framework: F,
): SupportedStyle<F> {
export function getDefaultStyle<F extends SupportedFramework>(framework: F): SupportedStyle<F> {
return FRAMEWORK_STYLES[framework][0];
}
+3 -7
View File
@@ -1,4 +1,5 @@
import type { SupportedFramework, SupportedStyle } from '@/types/docs';
import { findFirstGuide } from '@/utils/docs/sidebar';
/**
@@ -11,16 +12,11 @@ import { findFirstGuide } from '@/utils/docs/sidebar';
* @returns The full docs URL to redirect to
* @throws Error if no guide is available for the given framework/style
*/
export function getDocsRedirectUrl<F extends SupportedFramework>(
framework: F,
style: SupportedStyle<F>,
): string {
export function getDocsRedirectUrl<F extends SupportedFramework>(framework: F, style: SupportedStyle<F>): string {
const firstGuide = findFirstGuide(framework, style);
if (!firstGuide) {
throw new Error(
`No guide available for framework "${framework}" and style "${style}"`,
);
throw new Error(`No guide available for framework "${framework}" and style "${style}"`);
}
return `/docs/framework/${framework}/style/${style}/${firstGuide}/`;
+5 -18
View File
@@ -1,12 +1,7 @@
import type { AnySupportedStyle, Guide, Section, Sidebar, SupportedFramework, SupportedStyle } from '@/types/docs';
import { sidebar } from '@/config/docs/sidebar';
import {
getAvailableStyles,
isSection,
} from '@/types/docs';
import { getAvailableStyles, isSection } from '@/types/docs';
/**
* Check if an item (Guide or Section) should be shown based on framework and style.
@@ -18,13 +13,8 @@ import {
* @param style - The currently selected style
* @returns true if the item should be visible
*/
function isItemVisible(
item: Guide | Section,
framework: SupportedFramework,
style: AnySupportedStyle,
): boolean {
const frameworkMatch
= !item.frameworks || item.frameworks.includes(framework);
function isItemVisible(item: Guide | Section, framework: SupportedFramework, style: AnySupportedStyle): boolean {
const frameworkMatch = !item.frameworks || item.frameworks.includes(framework);
const styleMatch = !item.styles || item.styles.includes(style);
return frameworkMatch && styleMatch;
}
@@ -133,10 +123,7 @@ export function getAllGuideSlugs(sidebarToExtract: Sidebar = sidebar): string[]
* @param sidebarToSearch - Optional sidebar to search (defaults to main sidebar config)
* @returns The guide object if found, null otherwise
*/
export function findGuideBySlug(
slug: string,
sidebarToSearch: Sidebar = sidebar,
): Guide | null {
export function findGuideBySlug(slug: string, sidebarToSearch: Sidebar = sidebar): Guide | null {
for (const item of sidebarToSearch) {
if (isSection(item)) {
// Recursively search section contents
+3 -6
View File
@@ -1,4 +1,5 @@
import type { ParseDataOptions } from 'astro/loaders';
import { glob } from 'astro/loaders';
/**
@@ -7,7 +8,7 @@ import { glob } from 'astro/loaders';
*/
type Parser = <TData extends Record<string, unknown>>(
options: ParseDataOptions<TData>,
originalEntry: string,
originalEntry: string
) => Promise<ParseDataOptions<TData>>;
type GlobWithParserOptions = Parameters<typeof glob>[0] & {
@@ -36,11 +37,7 @@ type GlobWithParserOptions = Parameters<typeof glob>[0] & {
* })
* ```
*/
export function globWithParser({
parser,
generateId,
...globOptions
}: GlobWithParserOptions) {
export function globWithParser({ parser, generateId, ...globOptions }: GlobWithParserOptions) {
/**
* Store mapping of transformed IDs to original entry filenames.
* Created per-invocation to avoid memory leaks across builds.