Skip to content

Commit

Permalink
feat(docs): new composable documentation (#1246)
Browse files Browse the repository at this point in the history
* feat: sidebar menu

* feat: dynamic pages

* feat: dynamic content building

* feat: new composables structure

* feat: update vitepress

* feat: dynamic categories

* feat: categories list

* feat: category link

* feat(vue-demo): update categories

* feat(vue-demo): lock conflict resolve

* feat(vue-demo): tags style

* feat(vue-demo): update pnpm lock file

* feat(composables): fix test

* feat(docs): changes after cr
  • Loading branch information
mdanilowicz authored Sep 10, 2024
1 parent 6111185 commit 04e1b87
Show file tree
Hide file tree
Showing 110 changed files with 17,749 additions and 10,552 deletions.
64 changes: 60 additions & 4 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { defineConfigWithTheme } from "vitepress";
import type { Config as ThemeConfig } from "vitepress-shopware-docs";
import baseConfig from "vitepress-shopware-docs/config";
import { baseConfig } from "@shopware-docs/vitepress";
import nav from "./navigation";
import { SearchPlugin } from "vitepress-plugin-search";
import { CmsBaseReference } from "./theme/typer/cms-base-plugin";
import { ReadmeBasedReference } from "./theme/typer/plugin";
import { ReadmeLoader } from "./theme/typer/readme-loader";
import { ComposablesBuilder } from "./theme/typer/composables-builder";
import { resolve } from "path";
import data from "./data/composables.data";

const composables = await data.load(null);

export const sidebar = [
{
Expand All @@ -28,6 +33,7 @@ export const sidebar = [
{
text: "Composables",
link: "/framework/composables.html",
collapsed: true,
items: [
{
text: "Context Composables",
Expand Down Expand Up @@ -57,6 +63,7 @@ export const sidebar = [
{
text: "Setup Templates",
link: "/getting-started/templates.html",
collapsed: true,
items: [
{
text: "Demo Store",
Expand Down Expand Up @@ -85,6 +92,7 @@ export const sidebar = [
{
text: "CMS",
link: "/getting-started/cms/",
collapsed: true,
items: [
{
text: "Custom Elements",
Expand Down Expand Up @@ -119,6 +127,7 @@ export const sidebar = [
{
text: "E-Commerce",
link: "/getting-started/e-commerce/",
collapsed: true,
items: [
{
text: "Product Listing",
Expand Down Expand Up @@ -147,6 +156,7 @@ export const sidebar = [
{
text: "Features",
link: "/getting-started/features/",
collapsed: true,
items: [
{
text: "Sitemap",
Expand All @@ -173,6 +183,7 @@ export const sidebar = [
{
text: "Page elements",
link: "/getting-started/page-elements/",
collapsed: true,
items: [
{
text: "Breadcrumbs",
Expand All @@ -193,6 +204,7 @@ export const sidebar = [
{
text: "Examples",
link: "/getting-started/page-elements/examples/",
collapsed: true,
items: [
{
text: "Cart",
Expand Down Expand Up @@ -228,6 +240,7 @@ export const sidebar = [
{
text: "Error Handling",
link: "/packages/api-client.html#error-handling",
collapsed: true,
// TODO: remove this subpages after 2024-08
items: [
{
Expand All @@ -251,10 +264,12 @@ export const sidebar = [
{
text: "Integrations",
link: "/resources/integrations/",
collapsed: true,
items: [
{
text: "CMS",
link: "/resources/integrations/cms/",
collapsed: true,
items: [
{
text: "Storyblok",
Expand All @@ -269,6 +284,7 @@ export const sidebar = [
{
text: "Commercial",
link: "/resources/integrations/commercial/",
collapsed: true,
items: [
{
text: "B2B Quick Order",
Expand All @@ -287,6 +303,7 @@ export const sidebar = [
{
text: "Payments",
link: "/resources/integrations/payments/",
collapsed: true,
items: [
{
text: "Amazon Pay",
Expand All @@ -312,14 +329,18 @@ export const sidebar = [
},
{
text: "PACKAGE REFERENCE",
collapsed: true,
link: "/packages/",
items: [
{
text: "API Client",
link: "/packages/api-client.html",
},
{ text: "Composables", link: "/packages/composables.html" },
{
text: "Composables",
link: "/packages/composables/",
collapsed: true,
items: composables?.composablesList ?? [],
},
{ text: "CMS Base", link: "/packages/cms-base.html" },
{ text: "Nuxt3 Module", link: "/packages/nuxt3-module.html" },
{ text: "Helpers", link: "/packages/helpers.html" },
Expand All @@ -334,7 +355,7 @@ interface ThemeConfigExtended extends ThemeConfig {
}

export default defineConfigWithTheme<ThemeConfigExtended>({
extends: baseConfig,
extends: baseConfig.default,
lang: "en-US",
title: "Shopware Frontends",
description: "Documentation for Shopware developers",
Expand Down Expand Up @@ -436,6 +457,15 @@ export default defineConfigWithTheme<ThemeConfigExtended>({
minify: "terser",
chunkSizeWarningLimit: Infinity,
ssr: false,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("mermaid")) {
return "mermaid";
}
},
},
},
},
json: {
stringify: true,
Expand All @@ -445,7 +475,33 @@ export default defineConfigWithTheme<ThemeConfigExtended>({
ReadmeBasedReference(),
CmsBaseReference(),
ReadmeLoader(),
ComposablesBuilder(),
],
resolve: {
alias: {
"@node_modules": resolve(process.cwd(), "node_modules"),
"../composables/edit-link": resolve(
__dirname,
"../node_modules/vitepress-shopware-docs/src/shopware/composables/edit-link.ts",
),
"./VPNavBarTitle.vue": resolve(
__dirname,
"../node_modules/vitepress-shopware-docs/src/shopware/components/override/VPNavBarTitle.vue",
),
"./VPAlgoliaSearchBox.vue": resolve(
__dirname,
"../node_modules/vitepress-shopware-docs/src/shopware/components/override/VPAlgoliaSearchBox.vue",
),
"../NotFound.vue": resolve(
__dirname,
"../node_modules/vitepress-shopware-docs/src/shopware/components/override/NotFound.vue",
),
"../SwagRelatedArticles.vue": resolve(
__dirname,
"../node_modules/vitepress-shopware-docs/src/shopware/components/SwagRelatedArticles.vue",
),
},
},
},
vue: {
reactivityTransform: true,
Expand Down
40 changes: 40 additions & 0 deletions apps/docs/.vitepress/data/composables.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defineLoader } from "vitepress";
import { resolve } from "path";
import { extract } from "ts-dox";
import { readdirSync } from "fs";
export interface Data {
composablesList: { text: string; link: string; category: string }[];
}

declare const data: Data;
export { data };

export default defineLoader({
async load(): Promise<Data> {
const composablesList = readdirSync("../../packages/composables/src/", {
withFileTypes: true,
})
.filter(
(element) => element.isDirectory() && element.name.startsWith("use"),
)
.map((element) => {
const file = extract(
resolve(
`../../packages/composables/src/${element.name}/${element.name}.ts`,
),
);
return {
text: element.name,
link: `/packages/composables/${element.name}`,
category:
(file?.functions[element.name]?.docs.category ||
file?.functions[`${element.name}Function`]?.docs.category) ??
"",
};
});

return {
composablesList,
};
},
});
51 changes: 51 additions & 0 deletions apps/docs/.vitepress/theme/components/ComposablesList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div
v-for="(category, index) in categoryTreeData"
:id="`${index}${new Date().getTime()}`"
>
<h3 class="!mb-2" :id="normalizeAnchorText(index.toString())" tabindex="-1">
{{ index }}
<a
class="header-anchor !top-0"
:href="`#${normalizeAnchorText(index.toString())}`"
aria-label='Permalink to "Test"'
></a>
</h3>
<ul class="flex flex-wrap gap-3 !p-0 !m-0">
<li
v-for="(composable, index) in category"
:key="`${composable + new Date().getTime()}`"
class="list-none !m-0 bg-gray-100 rounded-sm leading-4"
>
<a
:href="`/packages/composables/${composable}`"
class="text-sm p-2 !no-underline !text-gray-800"
>{{ composable }}</a
>
</li>
</ul>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
import { data } from "../../data/composables.data";
import { normalizeAnchorText } from "../typer/utils";
const categoryTreeData = computed(() => {
const categoryTree: { [key: string]: string[] } = {};
data.composablesList.forEach((composable) => {
const categories = composable.category.split(",");
categories.forEach((category) => {
if (!categoryTree[category]) {
categoryTree[category] = [];
}
categoryTree[category].push(composable.text);
});
});
return categoryTree;
});
</script>
3 changes: 3 additions & 0 deletions apps/docs/.vitepress/theme/components/DemoBlock.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<slot />
</template>
33 changes: 16 additions & 17 deletions apps/docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// import './styles/index.css'
import { h, App } from "vue";
import { VPTheme } from "vitepress-shopware-docs";
import { App } from "vue";
import { SWAGTheme } from "vitepress-shopware-docs";
import PageRef from "./components/PageRef.vue";
import DemoBlock from "./components/DemoBlock.vue";
import ComposablesList from "./components/ComposablesList.vue";
// Ai component
// import AI from "./components/AI.vue";
import "./custom.css";

export default Object.assign({}, VPTheme, {
Layout: () => {
// @ts-ignore
return h(VPTheme.Layout, null, {
// banner: () => h(Banner),
// "content-top": () => h("h1", "We have important Announcement!"),
// 'sidebar-top': () => h(PreferenceSwitch),
// 'aside-mid': () => h(SponsorsAside),
// 'aside-bottom': () => h(VueJobs)
});
export default Object.assign(
{
...SWAGTheme(),
},
enhanceApp({ app }: { app: App }) {
app.component("PageRef", PageRef);
// app.component("AI", AI);
// app.provide('some-injection-key-if-needed', VALUE)
{
enhanceApp({ app }: { app: App }) {
app.component("PageRef", PageRef);
app.component("DemoBlock", DemoBlock);
app.component("ComposablesList", ComposablesList);
// app.component("AI", AI);
// app.provide('some-injection-key-if-needed', VALUE)
},
},
});
);
Loading

0 comments on commit 04e1b87

Please sign in to comment.