|
| 1 | +import type { DefaultTheme, MarkdownOptions } from 'vitepress'; |
| 2 | + |
| 3 | +import { transformerTwoslash } from '@shikijs/vitepress-twoslash'; |
| 4 | +import tailwindcss from '@tailwindcss/vite'; |
| 5 | +import { fileURLToPath } from 'node:url'; |
| 6 | +import { defineConfig } from 'vitepress'; |
| 7 | + |
| 8 | +import { getContentItems } from '../../src/utils'; |
| 9 | + |
| 10 | +export default async () => { |
| 11 | + const contentItems = await getContentItems(); |
| 12 | + const sidebarContentItems = contentItems.reduce<DefaultTheme.SidebarItem[]>( |
| 13 | + (categoryItems, contentItem) => { |
| 14 | + const category = categoryItems.find((group) => group.text === contentItem.category); |
| 15 | + |
| 16 | + if (!category) { |
| 17 | + categoryItems.push({ |
| 18 | + text: contentItem.category, |
| 19 | + items: [contentItem] |
| 20 | + }); |
| 21 | + } else { |
| 22 | + category.items!.push(contentItem); |
| 23 | + } |
| 24 | + |
| 25 | + return categoryItems; |
| 26 | + }, |
| 27 | + [] |
| 28 | + ); |
| 29 | + |
| 30 | + return defineConfig({ |
| 31 | + base: '/', |
| 32 | + title: 'reactuse', |
| 33 | + titleTemplate: false, |
| 34 | + cleanUrls: true, |
| 35 | + sitemap: { |
| 36 | + hostname: 'https://reactuse.org' |
| 37 | + }, |
| 38 | + description: |
| 39 | + 'Improve your react applications with our library 📦 designed for comfort and speed', |
| 40 | + markdown: { |
| 41 | + codeTransformers: [ |
| 42 | + transformerTwoslash({ |
| 43 | + twoslashOptions: { |
| 44 | + compilerOptions: { |
| 45 | + ignoreDeprecations: '6.0' |
| 46 | + } |
| 47 | + } |
| 48 | + }) |
| 49 | + ], |
| 50 | + languages: ['js', 'jsx', 'ts', 'tsx'] |
| 51 | + } as unknown as MarkdownOptions, |
| 52 | + vite: { |
| 53 | + plugins: [tailwindcss()], |
| 54 | + resolve: { |
| 55 | + alias: { |
| 56 | + '@siberiacancode/reactuse': fileURLToPath(new URL('../../../core/src', import.meta.url)), |
| 57 | + '@siberiacancode/docs': fileURLToPath(new URL('../../src', import.meta.url)), |
| 58 | + '@': fileURLToPath(new URL('../../../core/src', import.meta.url)) |
| 59 | + } |
| 60 | + } |
| 61 | + }, |
| 62 | + transformPageData: (pageData) => { |
| 63 | + pageData.frontmatter.head ??= []; |
| 64 | + pageData.frontmatter.head.push([ |
| 65 | + 'meta', |
| 66 | + { |
| 67 | + name: 'og:image', |
| 68 | + content: |
| 69 | + 'https://repository-images.githubusercontent.com/799880708/0afee0cb-ca48-40a2-9c38-dc5b64ebdf65' |
| 70 | + } |
| 71 | + ]); |
| 72 | + |
| 73 | + if (pageData.relativePath.includes('hooks') && pageData.params?.name) { |
| 74 | + const name = pageData.params.name as string; |
| 75 | + const description = (pageData.params.description as string) ?? ''; |
| 76 | + |
| 77 | + pageData.title = `${name} React hook Reactuse`; |
| 78 | + pageData.description = description; |
| 79 | + |
| 80 | + pageData.frontmatter.head.push( |
| 81 | + ['meta', { property: 'og:title', content: pageData.title }], |
| 82 | + ['meta', { property: 'og:description', content: pageData.description }] |
| 83 | + ); |
| 84 | + } |
| 85 | + }, |
| 86 | + head: [ |
| 87 | + ['meta', { name: 'algolia-site-verification', content: '60FB6E25551CE504' }], |
| 88 | + ['link', { rel: 'icon', href: '/favicon.ico' }], |
| 89 | + ['link', { rel: 'manifest', href: '/manifest.json' }], |
| 90 | + [ |
| 91 | + 'script', |
| 92 | + { type: 'text/javascript' }, |
| 93 | + `(function(m,e,t,r,i,k,a){ |
| 94 | + m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; |
| 95 | + m[i].l=1*new Date(); |
| 96 | + for (var j = 0; j < document.scripts.length; j++) { |
| 97 | + if (document.scripts[j].src === r) { return; } |
| 98 | + } |
| 99 | + k=e.createElement(t),a=e.getElementsByTagName(t)[0], |
| 100 | + k.async=1,k.src=r,a.parentNode.insertBefore(k,a) |
| 101 | + })(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); |
| 102 | + |
| 103 | + ym(102942267, "init", { |
| 104 | + clickmap:true, |
| 105 | + trackLinks:true, |
| 106 | + accurateTrackBounce:true |
| 107 | + });` |
| 108 | + ], |
| 109 | + [ |
| 110 | + 'noscript', |
| 111 | + {}, |
| 112 | + `<div><img src="https://mc.yandex.ru/watch/102942267" style="position:absolute; left:-9999px;" alt="" /></div>` |
| 113 | + ], |
| 114 | + |
| 115 | + [ |
| 116 | + 'script', |
| 117 | + {}, |
| 118 | + `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': |
| 119 | + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], |
| 120 | + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= |
| 121 | + 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); |
| 122 | + })(window,document,'script','dataLayer','GTM-5SMCHX9Z');` |
| 123 | + ], |
| 124 | + |
| 125 | + [ |
| 126 | + 'script', |
| 127 | + { |
| 128 | + async: '', |
| 129 | + src: 'https://www.googletagmanager.com/gtag/js?id=G-RRECQP6XBW' |
| 130 | + } |
| 131 | + ], |
| 132 | + |
| 133 | + [ |
| 134 | + 'script', |
| 135 | + {}, |
| 136 | + `window.dataLayer = window.dataLayer || []; |
| 137 | + function gtag(){dataLayer.push(arguments);} |
| 138 | + gtag('js', new Date()); |
| 139 | + gtag('config', 'G-RRECQP6XBW', { |
| 140 | + anonymize_ip: true, |
| 141 | + client_storage: 'none', |
| 142 | + allow_google_signals: false, |
| 143 | + allow_ad_personalization_signals: false |
| 144 | + });` |
| 145 | + ] |
| 146 | + ], |
| 147 | + locales: { |
| 148 | + root: { |
| 149 | + label: 'English', |
| 150 | + lang: 'en', |
| 151 | + themeConfig: { |
| 152 | + logo: { |
| 153 | + src: '/logo.svg', |
| 154 | + alt: 'reactuse' |
| 155 | + }, |
| 156 | + footer: { |
| 157 | + message: 'Released under the MIT License.', |
| 158 | + copyright: `Copyright © ${new Date().getFullYear()} siberiacancode` |
| 159 | + }, |
| 160 | + editLink: { |
| 161 | + pattern: ({ filePath, params }) => { |
| 162 | + if (filePath.includes('hooks') && params?.name) { |
| 163 | + return `https://github.com/siberiacancode/reactuse/blob/main/packages/core/src/hooks/${params.name}/${params.name}.ts`; |
| 164 | + } else { |
| 165 | + return `https://github.com/siberiacancode/reactuse/blob/main/packages/docs/app/${filePath}`; |
| 166 | + } |
| 167 | + }, |
| 168 | + text: 'Suggest changes to this page' |
| 169 | + }, |
| 170 | + nav: [ |
| 171 | + { text: 'Home', link: '/' }, |
| 172 | + { |
| 173 | + text: 'Functions', |
| 174 | + items: [ |
| 175 | + { text: 'Get Started', link: '/introduction' }, |
| 176 | + { text: 'Installation', link: '/installation' }, |
| 177 | + { text: 'Hooks', link: '/functions/hooks/useAsync.html' } |
| 178 | + ] |
| 179 | + } |
| 180 | + ], |
| 181 | + sidebar: [ |
| 182 | + { |
| 183 | + text: 'Getting started', |
| 184 | + items: [ |
| 185 | + { text: 'Introduction', link: '/introduction' }, |
| 186 | + { text: 'Installation', link: '/installation' }, |
| 187 | + { text: 'reactuse.json', link: '/reactuse-json' }, |
| 188 | + { text: 'CLI', link: '/cli' }, |
| 189 | + { text: 'target', link: '/target' }, |
| 190 | + { text: 'memoization', link: '/memoization' }, |
| 191 | + { text: 'optimization', link: '/optimization' } |
| 192 | + ] |
| 193 | + }, |
| 194 | + { |
| 195 | + text: 'Installation', |
| 196 | + items: [ |
| 197 | + { text: 'Vite', link: '/installation/vite' }, |
| 198 | + { text: 'Next.js', link: '/installation/nextjs' }, |
| 199 | + { text: 'Astro', link: '/installation/astro' }, |
| 200 | + { text: 'React Router', link: '/installation/react-router' }, |
| 201 | + { |
| 202 | + text: 'TanStack Router', |
| 203 | + link: '/installation/tanstack-router' |
| 204 | + }, |
| 205 | + { text: 'TanStack Start', link: '/installation/tanstack' }, |
| 206 | + { text: 'Preact', link: '/installation/preact' }, |
| 207 | + { text: 'Manual', link: '/installation/manual' } |
| 208 | + ] |
| 209 | + }, |
| 210 | + ...sidebarContentItems |
| 211 | + ] |
| 212 | + } |
| 213 | + } |
| 214 | + // ru: { |
| 215 | + // label: 'Русский', |
| 216 | + // lang: 'ru', |
| 217 | + // themeConfig: { |
| 218 | + // nav: [ |
| 219 | + // { text: 'Главная', link: '/ru' }, |
| 220 | + // { |
| 221 | + // text: 'Функции', |
| 222 | + // items: [{ text: 'Хуки', link: '/ru/functions/hooks' }] |
| 223 | + // } |
| 224 | + // ] |
| 225 | + // } |
| 226 | + // } |
| 227 | + }, |
| 228 | + themeConfig: { |
| 229 | + search: { |
| 230 | + provider: 'algolia', |
| 231 | + options: { |
| 232 | + appId: '62LROXAB1F', |
| 233 | + apiKey: '87ab8dd07b4aba02814c082d98e4b8a7', |
| 234 | + indexName: 'reactuse' |
| 235 | + } |
| 236 | + }, |
| 237 | + socialLinks: [ |
| 238 | + { icon: 'github', link: 'https://github.com/siberiacancode/reactuse' }, |
| 239 | + { |
| 240 | + icon: 'npm', |
| 241 | + link: 'https://www.npmjs.com/package/@siberiacancode/reactuse' |
| 242 | + } |
| 243 | + ] |
| 244 | + } |
| 245 | + }); |
| 246 | +}; |
0 commit comments