vuepress入門詳細(六)vuepressユーティリティプラグイン


vuepressユーティリティプラグイン


これらのプラグインはすべて公式に提供されており、一部のプラグインは私たちが実用的なデフォルトのテーマの時にすでにインストールされており、これ以上単独でインストールする必要はありません.一部のプラグインは私たちが単独でインストールする必要があります.具体的には以下の紹介をご覧ください

デフォルトのトピックに付属するプラグイン

  • @vuepress/plugin-active-header-links
  • @vuepress/plugin-nprogress
  • @vuepress/plugin-search
  • vuepress-plugin-container
  • vuepress-plugin-smooth-scroll
  • @vuepress/plugin-last-updated
  • @vuepress/plugin-register-components

  • :::warningデフォルトトピックに付属のプラグインで、直接構成して使用できます.デフォルトトピックを使用していない場合は、自分でダウンロードしてインストールする必要があります.::

    メニューハイライト


    名前:@vuepress/plugin-active-header-links効果:ページスクロール時にサイドバーリンクのプラグインを自動的にアクティブにします.効果は右の内容がスクロールしている間に、どこを見たか、左側のメニューが現在見ているディレクトリを自動的にハイライト表示します.

    インストール


    インストールなし
    yarn add -D @vuepress/plugin-active-header-links
    # OR npm install -D @vuepress/plugin-active-header-links
    

    コンフィギュレーション

    module.exports = {
        plugins: {
            '@vuepress/active-header-links':{
                sidebarLinkSelector: '.sidebar-link',
                headerAnchorSelector: '.header-anchor'
            }
        }
    }
    

    back-to-top


    名称:@vuepress/plugin-back-to-top効果:文章が下を見たとき、アイコンをクリックすると上部に戻ります

    インストール


    インストールなし
    yarn add -D @vuepress/plugin-back-to-top
    # OR npm install -D @vuepress/plugin-back-to-top
    

    コンフィギュレーション

    module.exports = {
        plugins: {
            '@vuepress/back-to-top': true
        }
    }
    

    last-updated


    名前:@vuepress/plugin-last-updated効果:文章の末尾に文章の更新日が自動的に表示されます.テーマはインストールされません.

    コンフィギュレーション

    module.exports = {
        plugins: {
            '@vuepress/last-updated': true
        }
    }
    

    デフォルトでは、このプラグインはページごとに13ビットのタイムスタンプを生成し、transformerに転送して任意のフォーマットに変換することができます.例:
    const moment = require('moment');
    
    module.exports = {
      plugins: {
          '@vuepress/last-updated':{
            transformer: (timestamp, lang) => {
              //        moment
              const moment = require('moment')
              moment.locale(lang)
              return moment(timestamp).fromNow()
            }
          }
      }
    }
    

    :::warning lastUpdatedはgitベースであるため、gitベースのプロジェクトでのみ有効にできます.また、git commitから使用されるタイムスタンプは、指定されたページの最初のコミット後にのみ表示され、ページの後続のコミット変更時にのみ更新されます.(私のプロジェクトはgitに基づいていないので、このプロジェクトを使用していません):

    進捗バー


    名前:@vuepress/nprogress効果:新しいページを開くと進捗バーが表示されます:::tipデフォルトトピックはインストールせず、デフォルト構成はtrueです.進捗バー機能がほしい場合は、何もしなくてもいいです.プログレスバー機能を閉じるにはfalse::

    コンフィギュレーション

    
     module.exports = {
       plugins: {
            '@vuepress/nprogress':false //   true,   false       
       }
     }
    

    グローバル検索


    名前:@vuepress/plugin-search効果:ナビゲーションバーでグローバル検索

    インストール


    デフォルトのトピックはインストールされていません
    yarn add -D @vuepress/plugin-search
    # OR npm install -D @vuepress/plugin-search
    

    コンフィギュレーション

    module.exports = {
      plugins: {
        '@vuepress/search': {
            search: true, //  false
            searchMaxSuggestions: 10 //    5
        }
      }
    }
    
  • search:検索機能をオンにし、デフォルトfalse
  • searchMaxSuggestions:最大10のバー数を表示します.デフォルトは5
  • です.

    Google analyticsプラグイン


    名称:@vuepress/plugin-google-analytics効果:ウェブサイトのトラフィックを統計し、ウェブサイトのいくつかの機能を分析します::warningこの機能を使用するには、Googleアカウントが必要で、Google analyticsを作成します
    プロジェクトがGoogle analyticsプラグインを使用している場合は、npmではなくYarnを使用してすべての依存をインストールすることをお勧めします.この場合、npmは誤った依存ツリーを生成するからです.::

    インストール


    個別のインストールが必要
    yarn add -D @vuepress/plugin-google-analytics
    

    コンフィギュレーション

    module.exports = {
        '@vuepress/google-analytics': {
            'ga': 'UA-166594741-1' // UA-00000000-0
        },
    }
    

    PWA


    PWAとは


    PWA(フルネーム:Progressive Web App)つまり、これは漸進的なWebアプリケーションです.主な特徴:
  • オフライン
  • Webアプリケーションをデスクトップにインストールできます.携帯電話側もデスクトップ
  • にインストールできます.
    名前:@vuepress/plugin-pwa
    効果:Webコンテンツが更新されたときに更新ボタンがあります.ページをデスクトップに保存して、appと同じようにすることができます.具体的に見ると

    インストール


    個別のインストールが必要
    yarn add -D @vuepress/plugin-pwa
    # OR npm install -D @vuepress/plugin-pwa
    

    コンフィギュレーション

    module.exports = {
         '@vuepress/pwa': {
                serviceWorker: true,
                updatePopup: {
                    message: "       ",
                    buttonText: "  "
                }
            }
    }
    

    :::tipはあなたのウェブサイトがPWAと完全に互換性があるように、あなたは必要です:
  • 在.vuepress/publicはManifestとicons
  • を提供する
  • 在.vuepress/config.js正しいhead linksを追加します(次の例を参照).

  • これは、VuePressにおいてPWAと完全に互換性がある例です.
    //head href      .vuepress  public
    module.exports = {
      head: [
        ['link', { rel: 'icon', href: '/logo.png' }],
        ['link', { rel: 'manifest', href: '/manifest.json' }],
        ['meta', { name: 'theme-color', content: '#3eaf7c' }],
        ['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
        ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
        ['link', { rel: 'apple-touch-icon', href: '/icons/apple-touch-icon-152x152.png' }],
        ['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
        ['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],
        ['meta', { name: 'msapplication-TileColor', content: '#000000' }]
      ],
      plugins: {
        '@vuepress/pwa': {
               serviceWorker: true,
               updatePopup: {
                   message: "       ",
                   buttonText: "  "
               }
           },
      }
    }
    

    以前のテスト用のmanifest.jsonファイルテンプレートは次のとおりです.
    {
      "name": "   ",
      "short_name": "   ",
      "start_url": "index.html",
      "display": "standalone",
      "background_color": "#3711f3",
      "description": "       ",
      "theme_color": "red",
      "icons": [
        {
          "src": "./image/pwalogo.png",
          "sizes": "144x144",
          "type": "image/png"
        }
      ],
      "related_applications": [
        {
          "platform": "web",
          "url": "https://play.google.com/store/apps/details?id=cheeaun.hackerweb"
        },
        {
          "platform": "play",
          "url": "https://play.google.com/store/apps/details?id=cheeaun.hackerweb"
        }
      ]
    }
    

    :::warning
  • vuepress
  • に従ってローカルに
  • build後tomcat容器に入れる必要がある
  • 更新内容は再build再配置する必要があります.ページを再ロードすると、リフレッシュボタンのプロンプトが表示されます.
  • localhostまたはhttpsのサイトのみがPWA機能を使用できます::
  • ::warningは異なるプラットフォームで、ドキュメントの表示の効果は異なっていて、最も良い最も全観覧する住所:vuepress実用的なプラグインはみんなを歓迎してブログに来て更に多い内容を理解します:java楽園::

    vuepress入門詳細ディレクトリ


    vuepress入門詳細(一)vuepress紹介vuepress入門詳細(二)vuepress快速構築vuepress入門詳細(三)vuepressディレクトリ構造vuepress入門詳細(四)vuepress基本構成vuepress入門詳細(五)vuepress Markdown詳細vuepress入門詳細(六)vuepress実用プラグインvuepress入門詳細(七)vuepressコメント機能vuepress入門詳細(八)vuepressサーバへの配備