mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
chore: consistent formatting (#47)
This commit is contained in:
@@ -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,4 +1,5 @@
|
||||
import rss from '@astrojs/rss';
|
||||
|
||||
import { getCollection } from 'astro:content';
|
||||
import { SITE_DESCRIPTION, SITE_TITLE } from '@/consts';
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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}/`;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user