1+ import * as path from "path" ;
2+ import * as fs from 'fs'
3+ import { fileURLToPath } from "url" ;
4+ import { defineConfig } from "vitepress" ;
5+ import { SearchPlugin } from 'vitepress-plugin-search'
6+ import PackageJSON from '../../package.json'
7+
8+ const __filename = fileURLToPath ( import . meta. url )
9+ const __dirname = path . dirname ( __filename )
10+
11+ const version = PackageJSON . version
12+ const docsPath = path . resolve ( __dirname , '../docs' )
13+
14+ /**
15+ * Generate list of all components grouped by functionality for sidebar menu
16+ *
17+ * @returns {import('vitepress').DefaultTheme.SidebarItem[] }
18+ */
19+ function getComponents ( ) {
20+ const sections = { }
21+
22+ fs . readdirSync ( path . resolve ( docsPath , 'components' ) )
23+ . forEach ( file => {
24+ const name = file . replace ( '.md' , '' )
25+ const words = name . split ( / (? = [ A - Z ] ) / )
26+ const section = words
27+ . slice ( 0 , ( words [ 1 ] === 'App' && words . length >= 3 ? 3 : 2 ) )
28+ . join ( '' )
29+ . replace ( / s $ / , '' ) // fix NcActions
30+ if ( ! ( section in sections ) ) sections [ section ] = [ ]
31+ sections [ section ] . push ( name )
32+ } )
33+
34+ return Object . keys ( sections )
35+ . sort ( )
36+ . map ( section => {
37+ // Get base component as first entry, sort is not enogh because of `NcActions` vs `NcActionX`
38+ const first = sections [ section ] . sort ( ( p , q ) => p . length - q . length ) [ 0 ]
39+ const other = sections [ section ] . filter ( p => p !== first ) . sort ( )
40+ return {
41+ text : section ,
42+ items : [
43+ first ,
44+ ...other
45+ ] . map ( file => ( { text : file , link : `/components/${ file } ` } ) )
46+ }
47+ } )
48+ }
49+
50+ export default defineConfig ( {
51+ title : '@nextcloud/vue' ,
52+ description : 'Vue.js components for Nextcloud app development' ,
53+
54+ ignoreDeadLinks : true ,
55+
56+ themeConfig : {
57+ logo : 'https://nextcloud.com/wp-content/uploads/2022/10/nextcloud-logo-blue-transparent.svg' ,
58+ nav : [
59+ { text : `${ version } ` , items : [
60+ { text : 'Changelog' , link : `https://github.com/nextcloud/nextcloud-vue/blob/v${ version } /CHANGELOG.md` } ,
61+ ] } ,
62+ ] ,
63+ sidebar : [
64+ {
65+ text : 'Components' ,
66+ collapsible : true ,
67+ collapsed : true ,
68+ items : getComponents ( ) ,
69+ } ,
70+ {
71+ items : [ {
72+ text : 'Directives' ,
73+ link : '/directives'
74+ } ]
75+ } ,
76+ ] ,
77+ socialLinks : [
78+ {
79+ icon : 'github' ,
80+ link : 'https://github.com/nextcloud/nextcloud-vue'
81+ }
82+ ] ,
83+ } ,
84+
85+ srcDir : '../docs' ,
86+
87+ markdown : {
88+ highlight : ( str , language , attr ) => hljs . highlight ( str , { language : language === 'vue' ? 'xml' : language } ) . value
89+ } ,
90+
91+ vite : {
92+ root : docsPath ,
93+ plugins : [ SearchPlugin ( ) ] ,
94+
95+ }
96+ } )
0 commit comments