aboutsummaryrefslogtreecommitdiff
path: root/docs/.vitepress/config.ts
blob: 82921c76be35b6ee76ed8ff322105c53eadc2ca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import { defineConfig } from 'vitepress';
import type { DefaultTheme } from 'vitepress/theme';
import { apiPages } from './api-pages';
import {
  algoliaIndex,
  commitHash,
  isReleaseBranch,
  version,
  versionBannerInfix,
  versionLabel,
  versionLinks,
} from './versions';

type SidebarItem = DefaultTheme.SidebarItem;

const description =
  'Generate massive amounts of fake (but reasonable) data for testing and development.';
const socialImage = 'https://fakerjs.dev/social-image.png';
const consoleDownload = isReleaseBranch
  ? `https://cdn.jsdelivr.net/npm/@faker-js/faker@${version}/+esm`
  : '/faker.js';
const consoleVersion = isReleaseBranch
  ? version
  : `${version.replace(/-.*$/, '')}-preview+${commitHash}`;

function getSideBarWithExpandedEntry(entryToExpand: string): SidebarItem[] {
  const links: SidebarItem[] = [
    {
      text: 'Guide',
      items: [
        {
          text: 'Getting Started',
          link: '/guide/',
        },
        {
          text: 'Usage',
          link: '/guide/usage',
        },
        {
          text: 'Localization',
          link: '/guide/localization',
        },
        {
          text: 'Frameworks',
          link: '/guide/frameworks',
        },
        {
          text: 'Randomizer',
          link: '/guide/randomizer',
        },
        {
          text: 'Unique Values',
          link: '/guide/unique',
        },
        {
          text: 'Upgrading to v10',
          link: '/guide/upgrading',
        },
      ],
    },
    {
      text: 'API',
      items: apiPages,
    },
    {
      text: 'Contributing',
      items: [
        {
          text: 'Code of Conduct',
          link: '/contributing/code-of-conduct',
        },
        {
          text: 'Report Bugs',
          link: '/contributing/report-bugs',
        },
        {
          text: 'Propose a Feature',
          link: '/contributing/propose-a-feature',
        },
        {
          text: 'Set up a Development Environment',
          link: '/contributing/set-up-a-development-environment',
        },
        {
          text: 'Submit a Pull Request',
          link: '/contributing/submit-a-pull-request',
        },
      ],
    },
    {
      text: 'About',
      items: [
        {
          text: 'Announcements',
          link: '/about/announcements',
          items: [
            { text: '2024-10-26', link: '/about/announcements/2024-10-26' },
            { text: '2022-09-08', link: '/about/announcements/2022-09-08' },
            { text: '2022-01-14', link: '/about/announcements/2022-01-14' },
          ],
        },
        {
          text: 'Roadmap',
          link: '/about/roadmap/',
          items: [
            {
              text: 'v9 - Tree-Shakeable Module-Functions',
              link: '/about/roadmap/v9',
            },
            { text: 'v8 - Make Faker Handier', link: '/about/roadmap/v8' },
            {
              text: 'v7 - Cleanup & Improvements',
              link: '/about/roadmap/v7',
            },
            { text: 'v6 - Continue Faker', link: '/about/roadmap/v6' },
          ],
        },
        {
          text: 'Team',
          link: '/about/team',
        },
      ],
    },
  ];

  for (const entry of links) {
    entry.collapsed = entry.text !== entryToExpand;
  }

  return links;
}

const config = defineConfig({
  title: 'Faker',
  description,

  head: [
    ['link', { rel: 'icon', href: '/logo.svg' }],
    ['meta', { name: 'theme-color', content: '#40af7c' }],
    ['meta', { name: 'og:title', content: 'FakerJS' }],
    ['meta', { name: 'og:description', content: description }],
    ['meta', { name: 'og:image', content: socialImage }],
    ['meta', { name: 'twitter:card', content: 'summary_large_image' }],
    ['meta', { name: 'twitter:title', content: 'FakerJS' }],
    ['meta', { name: 'twitter:description', content: description }],
    ['meta', { name: 'twitter:site', content: '@faker_js' }],
    ['meta', { name: 'twitter:image', content: socialImage }],
    ['meta', { name: 'twitter:image:alt', content: 'The FakerJS logo' }],
    ['link', { rel: 'me', href: 'https://fosstodon.org/@faker_js' }],
    [
      'script',
      { id: 'browser-console-faker' },
      `
const logStyle = 'background: rgba(16, 183, 127, 0.14); color: rgba(255, 255, 245, 0.86); padding: 0.5rem; display: inline-block;';
console.log(\`%cIf you would like to test Faker in the browser console, you can do so using 'await enableFaker()'.
If you would like to test Faker in a playground, visit https://new.fakerjs.dev.\`, logStyle);
async function enableFaker() {
  const imported = await import('${consoleDownload}');
  Object.assign(globalThis, imported);
  console.log(\`%cYou can now start using Faker v${consoleVersion}:
e.g. 'faker.food.description()' or 'fakerZH_CN.person.firstName()'
For other languages please refer to https://fakerjs.dev/guide/localization.html#available-locales
For a full list of all methods please refer to https://fakerjs.dev/api/\`, logStyle);
  enableFaker = () => imported; // Init only once
  return imported;
}
`,
    ],
  ],

  themeConfig: {
    logo: '/logo.svg',

    editLink: {
      pattern: 'https://github.com/faker-js/faker/edit/next/docs/:path',
      text: 'Suggest changes to this page',
    },

    socialLinks: [
      { icon: 'discord', link: 'https://chat.fakerjs.dev' },
      { icon: 'mastodon', link: 'https://fosstodon.org/@faker_js' },
      { icon: 'x', link: 'https://twitter.com/faker_js' },
      { icon: 'github', link: 'https://github.com/faker-js/faker' },
      { icon: 'npm', link: 'https://www.npmjs.com/package/@faker-js/faker' },
      {
        icon: {
          svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Open Collective</title><path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12c2.54 0 4.894-.79 6.834-2.135l-3.107-3.109a7.715 7.715 0 1 1 0-13.512l3.107-3.109A11.943 11.943 0 0 0 12 0zm9.865 5.166l-3.109 3.107A7.67 7.67 0 0 1 19.715 12a7.682 7.682 0 0 1-.959 3.727l3.109 3.107A11.943 11.943 0 0 0 24 12c0-2.54-.79-4.894-2.135-6.834z"/></svg>',
        },
        link: 'https://opencollective.com/fakerjs',
        ariaLabel: 'Open Collective',
      },
    ],

    algolia:
      process.env.API_KEY == null || process.env.APP_ID == null
        ? undefined
        : {
            apiKey: process.env.API_KEY,
            appId: process.env.APP_ID,
            indexName: algoliaIndex,
          },

    footer: {
      message: 'Released under the MIT License.',
      copyright: 'Copyright © 2022-present Faker.',
    },

    nav: [
      { text: 'Guide', activeMatch: `^/guide/`, link: '/guide/' },
      {
        text: 'API',
        activeMatch: `^/api/`,
        link: '/api/',
      },
      {
        text: 'Try it',
        items: [
          { text: 'StackBlitz ', link: 'https://fakerjs.dev/new' },
          { text: 'Browser Console ', link: '/guide/usage.html#browser' },
        ],
      },
      {
        text: 'About',
        activeMatch: `^/about/`,
        items: [
          {
            text: 'Announcements',
            link: '/about/announcements',
          },
          {
            text: 'Roadmap',
            link: '/about/roadmap/',
          },
          {
            text: 'Team',
            link: '/about/team',
          },
        ],
      },
      {
        text: versionLabel,
        items: [
          {
            text: 'Release Notes',
            link: 'https://github.com/faker-js/faker/releases',
          },
          ...versionLinks.map(({ version, link }) => ({
            text: version,
            link,
          })),
        ],
      },
    ],

    sidebar: {
      '/guide/': getSideBarWithExpandedEntry('Guide'),
      '/api/': getSideBarWithExpandedEntry('API'),
      '/contributing/': getSideBarWithExpandedEntry('Contributing'),
      '/about/': getSideBarWithExpandedEntry('About'),
    },
  },

  vite: {
    define: {
      __BANNER__: versionBannerInfix ?? false,
    },
  },
});

if (versionBannerInfix) {
  config.head?.push([
    'script',
    { id: 'restore-banner-preference' },
    `
(() => {
  const restore = (key, cls, def = false) => {
    const saved = localStorage.getItem(key);
    if (saved ? saved !== 'false' && new Date() < saved : def) {
      document.documentElement.classList.add(cls);
    }
  };
  restore('faker-version-banner', 'banner-dismissed');
})();`,
  ]);
}

export default config;