<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 生成器(Generator) 生成器根據處理后的原始文件建立路由。 ## 概要 ``` hexo.extend.generator.register(name, functionlocals{}); ``` 在函數中會傳入一個 `locals` 參數,等同于 [網站變量](variables.html#網站變量),請盡量利用此參數取得網站數據,避免直接存取資料庫。 ## 更新路由 ``` hexo.extend.generator.register('test'functionlocals{ // Object return path: 'foo' data: 'foo' }; // Array return {path: 'foo''foo' {path: 'bar''bar' ];}); ``` | 屬性 | 描述 | | --- | --- | | `path` | 路徑。不可包含開頭的 `/`。 | | `data` | 數據 | | `layout` | 布局。指定用于渲染的模板,可為字符串或數組,如果省略此屬性的話則會直接輸出 `data`。 | 在原始文件更新時,Hexo 會執行所有生成器并重建路由,**請直接回傳資料,不要直接操作路由**。 ## 范例 ### 歸檔頁面 在 `archives/index.html` 建立一歸檔頁面,把所有文章當作資料傳入模板內,這個資料也就等同于模板中的 `page` 變量。 然后,設置 `layout` 屬性好讓 Hexo 使用主題模板來渲染,在此例中同時設定了兩個布局,當 `archive` 布局不存在時,會繼續嘗試 `index` 布局。 ``` hexo.extend.generator.register('archive'functionlocals{ return path: 'archives/index.html' data: locals.posts, layout: ['archive''index' }}); ``` ### 有分頁的歸檔頁面 您可以通過 [hexo-pagination](https://github.com/hexojs/hexo-pagination) 這個方便的官方工具來輕松建立分頁歸檔。 ``` varrequire'hexo-pagination' hexo.extend.generator.register('archive'functionlocals{ return'archives/index.html' perPage: 10 layout: ['archive''index' data: {} });}); ``` ### 生成所有文章 遍歷 `locals.posts` 中的所有文章并生成所有文章的路由。 ``` hexo.extend.generator.register('post'functionlocals{ returnfunctionpost{ return path: post.path, data: post, layout: 'post' }; });}); ``` ### 復制文件 這次不直接在 `data` 中返回數據而是返回一個函數,如此一來這個路由唯有在使用時才會建立 `fs.ReadStream`。 ``` varrequire'hexo-fs' hexo.extend.generator.register('asset'functionlocals{ return path: 'file.txt' data: function{ return'path/to/file.txt' } };}); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看