From 34e0efd12cbd579116f1f3d1f090fe618adf3c05 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Fri, 23 Feb 2024 17:10:08 +0100 Subject: [PATCH] Adjusted to index.data changes to TS --- .../{indexFilter.js => indexFilter.ts} | 36 +++++++++++-------- advanced/{index.data.js => index.data.ts} | 2 +- advanced/index.md | 2 +- cds/{index.data.js => index.data.ts} | 2 +- cds/index.md | 2 +- guides/{index.data.js => index.data.ts} | 2 +- guides/index.md | 2 +- .../security/{index.data.js => index.data.ts} | 2 +- guides/security/index.md | 2 +- java/developing-applications/index.md | 4 +-- java/{index.data.js => index.data.ts} | 2 +- java/index.md | 2 +- java/operating-applications/index.md | 4 +-- 13 files changed, 35 insertions(+), 29 deletions(-) rename .vitepress/theme/components/{indexFilter.js => indexFilter.ts} (52%) rename advanced/{index.data.js => index.data.ts} (80%) rename cds/{index.data.js => index.data.ts} (80%) rename guides/{index.data.js => index.data.ts} (80%) rename guides/security/{index.data.js => index.data.ts} (98%) rename java/{index.data.js => index.data.ts} (80%) diff --git a/.vitepress/theme/components/indexFilter.js b/.vitepress/theme/components/indexFilter.ts similarity index 52% rename from .vitepress/theme/components/indexFilter.js rename to .vitepress/theme/components/indexFilter.ts index fcb6527921..2a5d4a2066 100644 --- a/.vitepress/theme/components/indexFilter.js +++ b/.vitepress/theme/components/indexFilter.ts @@ -1,7 +1,14 @@ const { base, themeConfig: { sidebar }} = global.VITEPRESS_CONFIG.site import { join } from 'node:path' +import { ContentData, DefaultTheme } from 'vitepress' -export default (pages, basePath) => { +type ContentDataCustom = ContentData & { + title?:string +} + +type SBItem = DefaultTheme.SidebarItem + +export default (pages:ContentDataCustom[], basePath:string):ContentDataCustom[] => { let items = findInItems(basePath, sidebar) || [] items = items.map(item => { return { ...item, link: item.link?.replace(/\.md$/, '') }}) const itemLinks = items.map(item => join(base, item.link||'')) @@ -13,29 +20,28 @@ export default (pages, basePath) => { return p }) .filter(p => { - const item = items.find(item => p.url.endsWith(item.link)) + const item = items.find(item => item.link && p.url.endsWith(item.link)) if (item) p.title = item.text return !!item }) .filter(p => !p.url.endsWith(basePath)) .sort((p1, p2) => itemLinks.indexOf(p1.url) - itemLinks.indexOf(p2.url)) - .map(p => { - // this data is inlined in each index page, so sparsely construct the final object - return { - url: p.url, - title: p.title, - frontmatter: { - synopsis: p.frontmatter.synopsis - } - } - }) + .map(p => ({ + url: p.url, + title: p.title, + frontmatter: { + synopsis: p.frontmatter.synopsis + }, + // this data is inlined in each index page, so omit unnecessary data + src:undefined, html:undefined, excerpt:undefined + })) } -function findInItems(url, items=[]) { +function findInItems(url:string, items:SBItem[]=[]):SBItem[]|undefined { let res = items.find(item => item.link?.includes(url)) if (res) return res.items for (const item of items) { - res = findInItems(url, item.items) - if (res) return res + const result = findInItems(url, item.items) + if (result) return result } } diff --git a/advanced/index.data.js b/advanced/index.data.ts similarity index 80% rename from advanced/index.data.js rename to advanced/index.data.ts index a104ade07f..b6b1f3bf30 100644 --- a/advanced/index.data.js +++ b/advanced/index.data.ts @@ -1,6 +1,6 @@ import { basename } from 'node:path' import { createContentLoader } from 'vitepress' -import filter from '../.vitepress/theme/components/indexFilter.js' +import filter from '../.vitepress/theme/components/indexFilter.ts' const basePath = basename(__dirname) export default createContentLoader(`**/${basePath}/*.md`, { diff --git a/advanced/index.md b/advanced/index.md index d6fee2d63b..aa0bc27ece 100644 --- a/advanced/index.md +++ b/advanced/index.md @@ -8,7 +8,7 @@ This section provides information on advanced topics and concepts that are not c
diff --git a/cds/index.data.js b/cds/index.data.ts similarity index 80% rename from cds/index.data.js rename to cds/index.data.ts index a104ade07f..b6b1f3bf30 100644 --- a/cds/index.data.js +++ b/cds/index.data.ts @@ -1,6 +1,6 @@ import { basename } from 'node:path' import { createContentLoader } from 'vitepress' -import filter from '../.vitepress/theme/components/indexFilter.js' +import filter from '../.vitepress/theme/components/indexFilter.ts' const basePath = basename(__dirname) export default createContentLoader(`**/${basePath}/*.md`, { diff --git a/cds/index.md b/cds/index.md index d6d870ea26..dfe074ad27 100644 --- a/cds/index.md +++ b/cds/index.md @@ -15,7 +15,7 @@ CDS models are plain JavaScript objects complying to the _[Core Schema Notation [See the Nature of Models for more details](models){.learn-more}
diff --git a/guides/index.data.js b/guides/index.data.ts similarity index 80% rename from guides/index.data.js rename to guides/index.data.ts index 035017975e..afc78f5488 100644 --- a/guides/index.data.js +++ b/guides/index.data.ts @@ -1,6 +1,6 @@ import { basename } from 'node:path' import { createContentLoader } from 'vitepress' -import filter from '../.vitepress/theme/components/indexFilter.js' +import filter from '../.vitepress/theme/components/indexFilter.ts' const basePath = basename(__dirname) diff --git a/guides/index.md b/guides/index.md index 1907a7f6fe..00e8c06701 100644 --- a/guides/index.md +++ b/guides/index.md @@ -13,7 +13,7 @@ The following figure illustrates a walkthrough of the most prominent tasks withi ![The graphic groups topics into three phases: Development, Deploy, Use. The development phase covers topics like domain modeling, sing and providing services, databases and frontends. The deploy phase covers the deployment as well as CI/CD, monitoring and publishing APIs and packages for reuse. The use phase is about the subscription flow of multitenant applications and about customizing and extending those applications. ](assets/cookbook-overview.drawio.svg)
diff --git a/guides/security/index.data.js b/guides/security/index.data.ts similarity index 98% rename from guides/security/index.data.js rename to guides/security/index.data.ts index d6d0dae787..6b4139e330 100644 --- a/guides/security/index.data.js +++ b/guides/security/index.data.ts @@ -1,6 +1,6 @@ import { basename } from 'node:path' import { createContentLoader } from 'vitepress' -import filter from '../../.vitepress/theme/components/indexFilter.js' +import filter from '../../.vitepress/theme/components/indexFilter.ts' const basePath = basename(__dirname) diff --git a/guides/security/index.md b/guides/security/index.md index d99680772a..43a23b3945 100644 --- a/guides/security/index.md +++ b/guides/security/index.md @@ -18,7 +18,7 @@ This guide addresses of CAP applications who need to understand how to develop, deploy and operate CAP applications in a secure way.
diff --git a/java/developing-applications/index.md b/java/developing-applications/index.md index 044d83033f..90e7ffbf90 100644 --- a/java/developing-applications/index.md +++ b/java/developing-applications/index.md @@ -1,7 +1,7 @@ --- synopsis: > Learn here about developing a CAP Java application. - + status: released --- @@ -10,7 +10,7 @@ status: released {{ $frontmatter.synopsis }} diff --git a/java/index.data.js b/java/index.data.ts similarity index 80% rename from java/index.data.js rename to java/index.data.ts index ce07e64359..c4b4fc21cc 100644 --- a/java/index.data.js +++ b/java/index.data.ts @@ -1,6 +1,6 @@ import { basename } from 'node:path' import { createContentLoader } from 'vitepress' -import filter from '../.vitepress/theme/components/indexFilter.js' +import filter from '../.vitepress/theme/components/indexFilter.ts' const basePath = basename(__dirname) diff --git a/java/index.md b/java/index.md index 50a2f3c364..a9b24dd65a 100644 --- a/java/index.md +++ b/java/index.md @@ -26,7 +26,7 @@ import { useData } from 'vitepress' const { theme } = useData() const { versions } = theme.value.capire -import { data as pages } from './index.data.js' +import { data as pages } from './index.data.ts'
diff --git a/java/operating-applications/index.md b/java/operating-applications/index.md index ca0977eef4..10bb848e13 100644 --- a/java/operating-applications/index.md +++ b/java/operating-applications/index.md @@ -1,7 +1,7 @@ --- synopsis: > Learn here about operating a CAP Java application. - + status: released --- @@ -10,7 +10,7 @@ status: released {{ $frontmatter.synopsis }}