Compare commits

..

No commits in common. "d02c0838981acc879fc7b246d3a5db57a9384724" and "a212258c078060299d4e974774508b57f95a94ee" have entirely different histories.

7 changed files with 21 additions and 167 deletions

View File

@ -3,21 +3,14 @@ import type { IconProps } from "./Icon";
import { Icon } from "./Icon";
import { Link } from "./Link";
import clsx from "clsx";
type QuickLinksProps = {
children: JSXElement;
class?: string;
};
export default function QuickLinks(props: QuickLinksProps) {
return (
<div
class={clsx(
"not-prose my-12 grid grid-cols-1 gap-6 sm:grid-cols-2",
props.class,
)}
>
<div class="not-prose my-12 grid grid-cols-1 gap-6 sm:grid-cols-2">
{props.children}
</div>
);
@ -27,7 +20,6 @@ type QuickLinkProps = {
title: string;
description: string;
href: string;
lastEdited?: Date;
icon: IconProps["icon"];
};
@ -37,26 +29,13 @@ QuickLinks.QuickLink = (props: QuickLinkProps) => (
<div class="relative overflow-hidden rounded-xl p-6">
<Icon icon={props.icon} color="blue" class="h-8 w-8" />
<h2 class="mt-4 font-display text-base text-slate-900 leading-5">
<h2 class="mt-4 font-display text-base text-slate-900">
<Link href={props.href}>
<span class="absolute -inset-px rounded-xl" />
{props.title}
</Link>
</h2>
{props.lastEdited && (
<p class="mt-2 mb-4 italic text-xs text-slate-500">
<span class="font-semibold">Dernière modification :</span>{" "}
<time datetime={props.lastEdited.toISOString()}>
{props.lastEdited.toLocaleDateString("fr-FR", {
year: "numeric",
month: "2-digit",
day: "2-digit",
})}
</time>
</p>
)}
<p class="mt-1 text-sm text-slate-700">{props.description}</p>
</div>
</div>

View File

@ -2,7 +2,6 @@ import type { JSXElement } from "solid-js";
import { PrevNextLinks } from "@/components/PrevNextLinks";
import { usePageContext } from "vike-solid/usePageContext";
import { LatestDocs } from "@/partials/LatestDocs";
import { clientOnly } from "vike-solid/clientOnly";
import { clock } from "solid-heroicons/outline";
import { navigation } from "@/libs/navigation";
@ -22,25 +21,21 @@ export function DocsLayout(props: DocsLayoutProps) {
return (
<>
<div class="flex">
<main
id="article-content"
class="max-w-2xl min-w-0 flex-auto px-4 py-16 lg:max-w-none lg:pr-0 lg:pl-8 xl:px-16 grow"
>
<article>
<DocsHeader
title={pageContext.exports.frontmatter?.title}
estimatedReadingTime={pageContext.exports.readingTime?.text}
/>
<Prose>{props.children}</Prose>
</article>
<PrevNextLinks />
</main>
<main
id="article-content"
class="max-w-2xl min-w-0 flex-auto px-4 py-16 lg:max-w-none lg:pr-0 lg:pl-8 xl:px-16 grow"
>
<article>
<DocsHeader
title={pageContext.exports.frontmatter?.title}
estimatedReadingTime={pageContext.exports.readingTime?.text}
/>
<Prose>{props.children}</Prose>
</article>
<PrevNextLinks />
</main>
<TableOfContents />
</div>
<LatestDocs />
<TableOfContents />
</>
);
}

View File

@ -3,8 +3,8 @@ import type { JSXElement } from "solid-js";
import { usePageContext } from "vike-solid/usePageContext";
import { SmoothScroll } from "@/components/SmoothScroll";
import { HeroSection } from "@/partials/HeroSection";
import { clientOnly } from "vike-solid/clientOnly";
import { Navigation } from "@/partials/Navigation";
import { clientOnly } from "vike-solid/clientOnly";
import { Header } from "@/partials/Header";
import { Footer } from "@/partials/Footer";
import { DocsLayout } from "./DocsLayout";
@ -40,10 +40,7 @@ export default function DefaultLayout(props: DefaultLayoutProps) {
<Navigation />
</div>
</div>
<div class="flex flex-col">
<DocsLayout>{props.children}</DocsLayout>
</div>
<DocsLayout>{props.children}</DocsLayout>
</div>
<Footer />

View File

@ -38,10 +38,5 @@ export async function data(pageContext: PageContext) {
return {
sections: doc?.sections || [],
frontmatter,
docs: docCache.orderByLastEdit({
limit: 2,
includedBasePaths: ["docs", "certifications"],
excludedFileNames: [cachePathname],
}),
};
}

View File

@ -1,31 +0,0 @@
import type { Data } from "@/pages/+data";
import QuickLinks from "@/components/QuickLinks";
import { useData } from "vike-solid/useData";
import { For } from "solid-js";
export function LatestDocs() {
const data = useData<Data>();
return (
<section class="bg-violet-200 rounded-md p-4 m-6">
<h2 class="font-display text-3xl tracking-tight text-slate-900 text-center">
Dernières documentations
</h2>
<QuickLinks class="!mb-0 !mt-6">
<For each={data.docs}>
{(doc) => (
<QuickLinks.QuickLink
title={doc.frontmatter?.title || ""}
description={doc.frontmatter?.description || ""}
lastEdited={doc.lastEdit}
href={doc.filePath}
icon="presets"
/>
)}
</For>
</QuickLinks>
</section>
);
}

View File

@ -27,9 +27,7 @@ function NavigationItem(props: NavigationItemProps) {
return props.section.links.some((link) => checkIsLinkActive(link));
};
const [isOpened, setIsOpened] = createSignal(
checkIsActive() || pageContext.urlPathname === "/",
);
const [isOpened, setIsOpened] = createSignal(checkIsActive());
createEffect(() => {
// If the current URL path is the same as the link's href, set isOpened to true

View File

@ -1,3 +1,5 @@
import type { FlexSearchData } from "./FlexSearchService";
import type { TableOfContents } from "@/remarkHeadingId";
import type { Node } from "@markdoc/markdoc";
import { slugifyWithCounter } from "@sindresorhus/slugify";
@ -14,8 +16,6 @@ export type SectionCache = {
frontmatter?: SectionFrontmatter;
markdocNode: Node;
sections: DocSection[];
lastEdit: Date;
filePath: string;
};
export type DocSection = {
@ -32,14 +32,6 @@ type SectionFrontmatter = {
tags: string[];
};
type OrderConfig = {
limit: number;
includedBasePaths: string[];
excludedBasePaths: string[];
includedFileNames: string[];
excludedFileNames: string[];
};
class DocCache {
private static readonly pagesDir = path.join(__dirname, "pages");
private static instance: DocCache | null = null;
@ -170,17 +162,12 @@ class DocCache {
.replace(/\+Page\.md(x)?$/, "")
.replace(/\/+/, "/")
.replace(/\/$/, "");
const lastEdit = new Date(
(await fs.stat(path.join(DocCache.pagesDir, file))).mtime,
);
this.cache.set(filePath, {
content,
frontmatter,
markdocNode,
sections: this.getTableOfContents(markdocNode),
lastEdit,
filePath,
});
}
@ -220,72 +207,6 @@ class DocCache {
return this.cache.get(file);
}
public orderByLastEdit(customConfig?: Partial<OrderConfig>): SectionCache[] {
const config: OrderConfig = {
excludedBasePaths: [],
includedBasePaths: [],
excludedFileNames: [],
includedFileNames: [],
limit: 0,
...customConfig,
};
const checkIfIncludedBasePath = (doc: SectionCache) => {
if (config.includedBasePaths.length > 0) {
return config.includedBasePaths.some((basePath) => {
return doc.filePath.startsWith(basePath);
});
}
return true;
};
const checkIfExcludedBasePaths = (doc: SectionCache) => {
if (config.excludedBasePaths.length > 0) {
return !config.excludedBasePaths.some((basePath) => {
return doc.filePath.startsWith(basePath);
});
}
return true;
};
const checkIfIncludedFileNames = (doc: SectionCache) => {
if (config.includedFileNames.length > 0) {
return config.includedFileNames.some((fileName) => {
return doc.filePath.includes(fileName);
});
}
return true;
};
const checkIfExcludedFileNames = (doc: SectionCache) => {
if (config.excludedFileNames.length > 0) {
return !config.excludedFileNames.some((fileName) => {
return doc.filePath.includes(fileName);
});
}
return true;
};
const sortedDocs = Array.from(this.cache.values())
.sort((a, b) => b.lastEdit.getTime() - a.lastEdit.getTime())
.filter((doc) => {
return [
checkIfIncludedBasePath(doc),
checkIfExcludedBasePaths(doc),
checkIfIncludedFileNames(doc),
checkIfExcludedFileNames(doc),
].every((check) => check === true);
});
if (config.limit > 0) return sortedDocs.slice(0, config.limit);
return sortedDocs;
}
public waitingForCache(timeout: 20000): Promise<void> {
const timer = hrtime();