美文网首页
hexo生成多站点方案

hexo生成多站点方案

作者: Front_小伪 | 来源:发表于2019-02-25 09:20 被阅读0次

    本文默认所有读者了解node 和 npm
    一、安装hexo
    https://hexo.io/zh-cn/docs/ 可以观看文档已经写的很详细了,本文不过多描述

    二、配置多站点
    利用自定义配置文件,多个站点建立多个对应的文件夹作为站点根目录,每个文件夹放一个配置文件custom.yml
    目录如下图:(lab sports 即是一个站点,sub-sites原来是source,我的项目有改动)


    目录展示

    三、配置文件内容展示

    # Hexo Configuration
    ## Docs: https://hexo.io/docs/configuration.html
    ## Source: https://github.com/hexojs/hexo/
    
    # Site
    title: title
    subtitle:
    description:
    keywords: 
    author: 
    language: 
    timezone:
    
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    product_code: sports
    url: http://yoursite.com
    root: /
    permalink: :title.html                 
    permalink_defaults:
    
    # Directory
    source_dir: sub-sites/sports    //子站点目录
    public_dir: public/sports           //打包后的目录
    tag_dir: tags
    archive_dir: archives
    category_dir: categories
    code_dir: downloads/code
    i18n_dir: :lang
    skip_render: 
    
    # Writing
    new_post_name: :title.md # File name of new posts
    default_layout: post
    titlecase: false # Transform title into titlecase
    external_link: true # Open external links in new tab
    filename_case: 0
    render_drafts: false
    post_asset_folder: false
    relative_link: false
    future: true
    highlight:
      enable: true
      line_number: true
      auto_detect: false
      tab_replace:
      
    # Home page setting
    # path: Root path for your blogs index page. (default = '')
    # per_page: Posts displayed per page. (0 = disable pagination)
    # order_by: Posts order. (Order by date descending by default)
    index_generator:
      path: ''
      per_page: 10
      order_by: -date
      
    # Category & Tag
    default_category: uncategorized
    category_map:
    tag_map:
    
    # Date / Time format
    ## Hexo uses Moment.js to parse and display date
    ## You can customize the date format as defined in
    ## http://momentjs.com/docs/#/displaying/format/
    date_format: YYYY-MM-DD
    time_format: HH:mm:ss
    
    # Pagination
    ## Set per_page to 0 to disable pagination
    per_page: 10
    pagination_dir: page
    
    # Extensions
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    theme: theme
    
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type:
    
    

    四、打包生成html

    hexo g --config /root/xxx/custom.yml (要打包子站点的配置文件)
    rm db.json     //每次打包子站点都要删掉生成的缓存数据文件 ,不然会把别的站点文件都打包进来,这步很重要
    打包后会在public里面生成对应文件的目录
    把public传到服务器即可
    

    总结
    按照这种方法,每个站点都会生成各自的静态资源(css,js),但其实静态资源是一样的放在根目录就好,这个我还没有想好怎么配置,目前的解决方案是 利用gulp打包生成静态资源,主题里面不放css,js文件。有好的想法的同学欢迎指导。有其他方案的也欢迎分享。

    相关文章

      网友评论

          本文标题:hexo生成多站点方案

          本文链接:https://www.haomeiwen.com/subject/gpqwyqtx.html