config.js 5.4 KB
Newer Older
D
DCloud_LXH 已提交
1
const path = require('path');
D
DCloud_LXH 已提交
2
const { slugify } = require('@vuepress/shared-utils')
D
DCloud_LXH 已提交
3
const highlight = require('@vuepress/markdown/lib/highlight')
D
DCloud_LXH 已提交
4 5 6
const translatePlugin = require('./markdown/translate')
const headerPlugin = require('./markdown/header')
const createSidebar = require('./markdown/createSidebar')
D
DCloud_LXH 已提交
7
const { simplifySlugText, tabs } = require('./utils')
D
DCloud_LXH 已提交
8
const copyOptions = require('./config/copy');
D
DCloud_LXH 已提交
9 10

const config = {
D
DCloud_LXH 已提交
11
  theme: 'vuepress-theme-uni-app-test',
D
DCloud_LXH 已提交
12
  title: 'uni-app官网',
D
DCloud_LXH 已提交
13
  description: 'uni-app,uniCloud,serverless',
D
DCloud_LXH 已提交
14
  evergreen: process.env.NODE_ENV === 'development',
D
DCloud_LXH 已提交
15 16 17 18
  head: [
    ['link', {
      rel: 'shortcut icon',
      type: 'image/x-icon',
study夏羽's avatar
study夏羽 已提交
19
      href: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/icon.png?v=1556263038788'
D
DCloud_LXH 已提交
20
    }],
D
DCloud_LXH 已提交
21 22 23
    ['meta', {
      name: 'viewport', content: 'width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0'
    }],
D
DCloud_LXH 已提交
24 25 26
    ['meta', {
      name: 'keywords', content: 'serverless,云开发,数字天堂,前端开发,web开发,小程序开发,跨平台,跨平台开发,跨端开发,混合开发,app开发,多端开发,开发工具,HTML5,vue,react,native,rn,flutter,weex,cordova,微信小程序,阿里小程序,支付宝小程序,百度小程序,头条小程序,抖音小程序,QQ小程序,快应用,流应用,云函数'
    }],
D
DCloud_LXH 已提交
27
    ['script', { src: `/js/redirect.js?${Date.now()}&v=${Date.now()}&version=${Date.now()}` }],
study夏羽's avatar
study夏羽 已提交
28
    ['script', { src: 'https://hm.baidu.com/hm.js?fe3b7a223fc08c795f0f4b6350703e6f' }],
A
Anne_LXM 已提交
29
    ['script', { src: '/miku-delivery-1.2.1.js' }],
D
DCloud_LXH 已提交
30
    ['script', { src: `/js/miku.js?${Date.now()}&v=${Date.now()}&version=${Date.now()}` }]
D
DCloud_LXH 已提交
31
  ],
D
DCloud_LXH 已提交
32 33 34 35 36
  locales: {
    '/': {
      lang: 'zh-CN',
    }
  },
D
DCloud_LXH 已提交
37
  themeConfig: {
study夏羽's avatar
study夏羽 已提交
38 39
    titleLogo: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png',
    logo: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/logo.png',
D
DCloud_LXH 已提交
40
    sidebar: createSidebar(tabs),
D
DCloud_LXH 已提交
41
    sidebarDepth: 0,
D
DCloud_LXH 已提交
42 43 44
    nextLinks: false,
    prevLinks: false,
    repo: 'dcloudio/uni-app',
D
DCloud_LXH 已提交
45
    docsRepo: 'https://gitcode.net/dcloud/unidocs-zh',
D
DCloud_LXH 已提交
46
    docsBranch: 'master',
D
DCloud_LXH 已提交
47 48 49
    docsDir: 'docs',
    editLinks: true,
    editLinkText: '帮助我们改善此页面!',
D
DCloud_LXH 已提交
50
    lastUpdated: '上次更新',
D
DCloud_LXH 已提交
51
    // smoothScroll: true,
52
    search: false,
53 54 55
    algolia: {
      apiKey: '2fdcc4e76c8e260671ad70065e60b2e7',
      indexName: 'zh-uniapp',
D
DCloud_LXH 已提交
56
      appId: 'PQIR5NL8CZ',
D
DCloud_LXH 已提交
57
      searchParameters: { hitsPerPage: 50 }
D
DCloud_LXH 已提交
58 59
    },
    isDevelopment: process.env.NODE_ENV === 'development'
D
DCloud_LXH 已提交
60 61
  },
  markdown: {
D
DCloud_LXH 已提交
62
    // toc: { includeLevel: [1, 2, 3, 4] },
D
DCloud_LXH 已提交
63
    slugify (str) {
D
DCloud_LXH 已提交
64
      if (typeof str !== 'string') return ''
D
DCloud_LXH 已提交
65

D
DCloud_LXH 已提交
66
      let slug = str
D
DCloud_LXH 已提交
67 68 69 70
      if (slug.includes('@')) {
        let array = slug.split('@')
        slug = array.length > 1 ? array[array.length - 1] : str
      } else {
D
DCloud_LXH 已提交
71
        slug = simplifySlugText(slug.toLowerCase()).trim()
D
DCloud_LXH 已提交
72 73 74 75
      }
      return slugify(slug)
    },
    extractHeaders: ['h1', 'h2', 'h3', 'h4'],
D
DCloud_LXH 已提交
76
    chainMarkdown (config) {
D
DCloud_LXH 已提交
77 78 79 80 81 82 83 84
      const extensionMap = {
        uts: 'ts'
      }
      config.options.highlight((str, lang) => {
        const extension = extensionMap[lang]
        return highlight(str, extension || lang)
      })

D
DCloud_LXH 已提交
85 86 87 88 89 90
      config
        .plugin('translate')
        .use(translatePlugin)
        .end()
        .plugin('convert-header')
        .use(headerPlugin)
D
DCloud_LXH 已提交
91 92 93
        .end()
        .plugin('normallize-link')
        .use(require('./markdown/normallizeLink'))
D
DCloud_LXH 已提交
94
        .end()
D
DCloud_LXH 已提交
95 96 97 98
				.plugin('img-add-attrs')
				.use(require('./markdown/img-add-attrs'))
        .end()
				.plugin('attrs')
D
DCloud_LXH 已提交
99 100 101 102
        .use(require('markdown-it-attrs'),[{
          leftDelimiter: '#{',
          rightDelimiter: '}'
        }])
D
DCloud_LXH 已提交
103 104 105 106 107 108
        .end()
        .plugin('task-lists')
        .use(require('markdown-it-task-lists'))
        .end()
        .plugin('inject-json-to-md')
        .use(require('./markdown/inject-json-to-md'))
D
DCloud_LXH 已提交
109
        .end()
D
DCloud_LXH 已提交
110
        .plugin('markdown-it-raw-table')
D
DCloud_LXH 已提交
111
        .use(require('markdown-it-raw-table'))
D
DCloud_LXH 已提交
112
    }
D
DCloud_LXH 已提交
113
  },
D
DCloud_LXH 已提交
114
  chainWebpack (config, isServer) {
D
DCloud_LXH 已提交
115 116 117 118 119
    config.resolve.alias.set(
      '@theme-config',
      path.resolve(process.cwd(), 'docs/.vuepress/config')
    )
  },
120
  patterns: ['**/!(_sidebar).md', '**/*.vue'],
D
DCloud_LXH 已提交
121
  plugins: [
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    ["vuepress-plugin-juejin-style-copy", copyOptions],
    [
      'named-chunks',
      {
        layoutChunkName: (layout) => 'layout-' + layout.componentName,
        pageChunkName: page => {
          const _context = page._context
          const pageHeaders = (page.headers || []).map(item => item.title).join(',')
          if (pageHeaders) {
            const originDescription = page.frontmatter.description || ''
            page.frontmatter = {
              ...page.frontmatter,
              description: `${_context.siteConfig.description ? `${_context.siteConfig.description},` : ''}${pageHeaders}${originDescription ? `,${originDescription}` : ''}`.slice(0, 150),
            }
          }
          const pagePath = page.path.indexOf('.html') === -1 ? page.path + 'index' : page.path
          const curPath = 'docs/' + pagePath.replace('docs/', '').substring(1).replace(/\.html/g, "")
          return curPath
        }
      }
    ]
D
DCloud_LXH 已提交
143 144
  ],
  /**
145
   *
D
DCloud_LXH 已提交
146 147
   * @param {string} path path: js 资源文件路径
   * @param {string} type type: 资源文件类型,取值有 script 等
148
   * @returns
D
DCloud_LXH 已提交
149 150
   */
  shouldPrefetch: (path, type) => {
151 152
    if (type === 'script') return path.includes('vendors~') || path.includes('layout-') || path.includes('index.')
    return false
D
DCloud_LXH 已提交
153
  }
D
DCloud_LXH 已提交
154 155
}

D
DCloud_LXH 已提交
156
module.exports = config