Configuration avancée

Apprenez à configurer les paramètres avancés du thème Solitude.

Comptage de mots

# --------------------------- début ---------------------------
# Comptage de mots
# 字数统计
# Avertissement : Veuillez d'abord installer le plugin hexo-wordcount.
# 警告: 请先安装 hexo-wordcount 插件。
wordcount: false
# --------------------------- fin ---------------------------

Installez le plugin hexo-wordcount

npm
pnpm
bun
yarn
npm i hexo-wordcount

Formules mathématiques

# --------------------------- début ---------------------------
# Katex
# Support des formules Latex
# Latex 公式支持
katex:
  enable: false
  # S'il faut charger sur chaque page
  # 是否在每个页面加载
  per_page: false
  # S'il faut activer la copie de formule
  # 是否启用复制公式
  copytex: false
# --------------------------- fin ---------------------------

Désinstallez hexo-render-marked

npm un hexo-renderer-marked

Installez hexo-renderer-markdown-it katex et @renbaoshuo/markdown-it-katex

npm
pnpm
bun
yarn
npm i hexo-renderer-markdown-it katex @renbaoshuo/markdown-it-katex

Ajoutez le contenu suivant à _config.yml

_config.yml
markdown:
  preset: 'default'
  render:
    html: true
    xhtmlOut: false
    langPrefix: 'language-'
    breaks: true
    linkify: true
    typographer: true
    quotes: '""'''
  enable_rules:
  disable_rules:
  plugins:
    - '@renbaoshuo/markdown-it-katex'
  anchors:
    level: 2
    collisionSuffix: ''
    permalink: false
    permalinkClass: 'header-anchor'
    permalinkSide: 'left'
    permalinkSymbol: '¶'
    case: 0
    separator: '-'
  images:
    lazyload: false
    prepend_root: false
    post_asset: false
  inline: false  # https://markdown-it.github.io/markdown-it/#MarkdownIt.renderInline

Activez l'élément de configuration

# --------------------------- début ---------------------------
# Katex
# Support des formules Latex
# Latex 公式支持
katex:
  enable: true
  # S'il faut charger sur chaque page
  # 是否在每个页面加载
  per_page: true
  # S'il faut activer la copie de formule
  # 是否启用复制公式
  copytex: false
# --------------------------- fin ---------------------------

Vérification du site web

# --------------------------- début ---------------------------
# Vérification
# 验证
verify_site:
  # - name: google-site-verification
  #   content: xxxxxx
  # - name: baidu-site-verification
  #   content: xxxxxxx
# --------------------------- fin ---------------------------

Ajoutez les codes de vérification pour chaque plateforme

Préfixe CSS

# --------------------------- début ---------------------------
# Préfixe CSS
# CSS 前缀
# Lorsqu'activé, il ajoutera automatiquement un préfixe au CSS (pour obtenir un meilleur support de navigateur), mais cela augmentera la taille du fichier CSS.
# 开启后会自动给 CSS 加前缀(以获得更好的浏览器支持),但这会增加 CSS 文件的大小。
css_prefix: false
# --------------------------- fin ---------------------------

Extension

# --------------------------- début ---------------------------
# Extension
# 扩展
extends:
  # Insérer dans head
  # 插入到 head
  head:
  #  - <script src="https://cdn.bootcdn.net/ajax/libs/pace/1.2.4/pace.min.js"></script>

  # Insérer dans body
  # 插入到 body
  body:
  #  - <script src="https://cdn.bootcdn.net/ajax/libs/pace/1.2.4/pace.min.js"></script>
# --------------------------- fin ---------------------------

Vous pouvez insérer des fichiers de site web personnalisés.

PWA

PWA est un moyen d'optimisation web. Le thème a été adapté dans une certaine mesure, mais la configuration est toujours requise. Le tutoriel de configuration est le suivant :

Installez les plugins hexo-swpp et swpp-backends

Exécutez dans le répertoire racine du blog :

npm
pnpm
bun
yarn
npm i hexo-swpp 
npm
pnpm
bun
yarn
npm i swpp-backends

Configurez PWA

Activez la configuration pwa du thème et activez swpp dans la configuration Hexo.

_config.solitude.yml
# Environ à la ligne 773
# --------------------------- début ---------------------------
# PWA
# Application Web Progressive
pwa:
  enable: true
  manifest: /manifest.json # manifest.json
  theme_color: "#006a73" # Couleur du thème
  mask_icon: /img/pwa/favicon.png # Icône de masque
  apple_touch_icon: /img/pwa/favicon.png # Icône Apple touch
  bookmark_icon: /img/pwa/favicon.png # Icône de signet
  favicon_32_32: /img/pwa/favicon_32.png # Icône 32x32
  favicon_16_16: /img/pwa/favicon_16.png # Icône 16x16
# --------------------------- fin ---------------------------

Ajoutez la configuration swpp en bas du fichier de configuration Hexo.

_config.yml
swpp:
  # 是否启用插件
  enable: false
  # 是否在发布前自动执行脚本
  # auto_exec: true

Créez un fichier manifest.json dans le répertoire source

{
    "name": "Nom du site web",
    "short_name": "Abréviation du nom du site web",
    "theme_color": "#006a73",
    "background_color": "#006a73",
    "display": "fullscreen",
    "scope": "/",
    "start_url": "/",
    "id": "/",
    "icons": [
      {
        "src": "/img/pwa/favicon_16.png",
        "sizes": "16x16",
        "type": "image/png",
        "purpose": "any"
      },
      {
        "src": "/img/pwa/favicon_16.png",
        "sizes": "16x16",
        "type": "image/png",
        "purpose": "maskable"
      },
      {
        "src": "/img/pwa/favicon_32.png",
        "sizes": "32x32",
        "type": "image/png",
        "purpose": "any"
      },
      {
        "src": "/img/pwa/favicon_32.png",
        "sizes": "32x32",
        "type": "image/png",
        "purpose": "maskable"
      },
      {
        "src": "/img/pwa/favicon.png",
        "sizes": "180x180",
        "type": "image/png",
        "purpose": "any"
      },
      {
        "src": "/img/pwa/favicon.png",
        "sizes": "180x180",
        "type": "image/png",
        "purpose": "maskable"
      }
    ],
    "splash_pages": null
}

Créez un fichier sw-rules.js dans le répertoire racine du blog

module.exports.config = {
  /** @type {?ServiceWorkerConfig|boolean} */
  serviceWorker: {
    escape: 1,
    cacheName: 'SolitudeCache',
    debug: false,
  },
  register: {
    onsuccess: undefined,
    onerror: () =>
      console.error(
        'Service Worker 注册失败!可能是由于您的浏览器不支持该功能!'
      ),
    builder: (root, framework, pluginConfig) => {
      const { onerror, onsuccess } = pluginConfig.register;
      return `
            <script>
                (() => {
                    const sw = navigator.serviceWorker;
                    const error = ${onerror && onerror.toString()};
                    if (!sw?.register('${new URL(root).pathname}sw.js')
                        ${onsuccess ? `?.then(${onsuccess.toString()})` : ""}
                        ?.catch(error)
                    ) error()
                })()
            </script>`;
    },
  },
  /** @type {?DomConfig|boolean} */
  dom: {
    /** @type {?VoidFunction} */
    onsuccess: () => {
      caches
        .match('https://id.v3/')
        .then((res) => {
          if (res)
            res.json().then((json) => {
              utils &&
                utils.snackbarShow(
                  `已刷新缓存,更新为${json.escape + '.' + json.global + '.' + json.local
                  }版本最新内容`,
                  false,
                  2500
                );
            });
          else console.info('未找到缓存');
        })
        .catch((error) => console.error('缓存匹配出错', error));
    },
  },
  /** @type {?VersionJsonConfig|boolean} */
  json: {
    /** @type {number} */
    maxHtml: 15,
    /** @type {number} */
    charLimit: 1024,
    /** @type {string[]} */
    merge: [],
    exclude: {
      /** @type {RegExp[]} */
      localhost: [],
      /** @type {RegExp[]} */
      other: [],
    },
  },
  /** @type {?ExternalMonitorConfig|boolean} */
  external: {
    /** @type {number} */
    timeout: 5000,
    /** 拉取文件时地并发限制 */
    concurrencyLimit: 100,
    /** @type {({head: string, tail: string}|function(string):string[])[]} */
    js: [],
    /** @type {RegExp[]} */
    stable: [
      /^https:\/\/npm\.elemecdn\.com\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
      /^https:\/\/cdn\.cbd\.int\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
      /^https:\/\/cdn\.jsdelivr\.net\/npm\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
    ],
    replacer: (srcUrl) => {
      if (srcUrl.startsWith('https://cdn.jsdelivr.net/npm/')) {
        const pathname = new URL(srcUrl).pathname;
        return [
          srcUrl,
          `https://cdn.cbd.int/${pathname}`,
          `https://npm.elemecdn.com/${pathname}`,
          `https://fastly.jsdelivr.net/npm/${pathname}`,
        ];
      } else {
        return srcUrl;
      }
    },
  },
};

module.exports.cacheRules = {
  simple: {
    clean: true,
    search: false,
    match: (url, $eject) =>
      url.host === $eject.domain && ['/404.html'].includes(url.pathname),
  },
  cdn: {
    clean: true,
    match: (url) =>
      [
        'cdn.cbd.int',
        'lf26-cdn-tos.bytecdntp.com',
        'lf6-cdn-tos.bytecdntp.com',
        'lf3-cdn-tos.bytecdntp.com',
        'lf9-cdn-tos.bytecdntp.com',
        'cdn.staticfile.org',
        'npm.elemecdn.com',
      ].includes(url.host) &&
      url.pathname.match(/\.(js|css|woff2|woff|ttf|cur)$/),
  },
};

module.exports.getSpareUrls = (srcUrl) => {
  if (srcUrl.startsWith('https://npm.elemecdn.com')) {
    return {
      timeout: 3000,
      list: [
        srcUrl,
        `https://fastly.jsdelivr.net/${new URL(srcUrl).pathname}`,
      ],
    };
  }
};

module.exports.ejectValues = (hexo, rules) => {
  return {
    domain: {
      prefix: 'const',
      value: new URL(hexo.config.url).host,
    },
  };
};

module.exports.skipRequest = (request) => request.url.startsWith("https://i0.hdslb.com") ||
  request.url.startsWith('https://meting.qjqq.cn') ||
  request.url.startsWith('https://api.i-meto.com');

Référence de structure de fichiers

Statistiques de visite Busuanzi

# --------------------------- start ---------------------------
# Busuanzi
busuanzi: false
# 0: Original / 1: Personnalisé
# 0: Version originale / 1: Version personnalisée
busuanzi_use: 0
# --------------------------- end ---------------------------

Google реклама

# --------------------------- start ---------------------------
# Google publicité
# Publicité Google
google_adsense:
  enable: false
  # Publicités automatiques
  # Publicités auto
  auto_ads: false
  # Publicités au niveau de la page
  # Publicités page-level
  enable_page_level_ads: true
  # Publicités carte latérale
  # Cartes publicitaires sidebar
  aside_card: true
  # Publicités carte d'article
  # Cartes publicitaires articles
  post_card: true
  # Publicités contenu d'article
  # Publicités dans le contenu
  post_content: true
  # Google Adsense js
  # JS publicité Google
  js: https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
  client: # ca-pub-XXXXXXXXXXXXXX
  slot: # 4236388782
# --------------------------- end ---------------------------

CDN

# --------------------------- début ---------------------------
# Ne pas modifier sauf si nécessaire
CDN:
  internal: local # local / cdnjs / jsdelivr / unpkg / custom
  third_party: custom # cdnjs / jsdelivr / unpkg / custom
  version: true # S'il faut utiliser le numéro de version
  custom_format: https://fastly.jsdelivr.net/npm/${name}@${version}/${min_file} # Format personnalisé
  # Remplacer directement les liens CDN par défaut (priorité la plus élevée)
  options:
    # algolia_search:
    # aplayer_css:
    # aplayer_js:
    # artalk_css:
    # artalk_js:
    # blueimp_md5:
    # busuanzi_js:
    # chart_js:
    # color_thief:
    # fancyapps_css:
    # fancyapps_ui:
    # fontawesome:
    # instantsearch:
    # katex:
    # katex_copytex:
    # lazyload:
    # medium_zoom:
    # mermaid_js:
    # meting_js:
    # pace_js:
    # pjax:
    # qrcode:
    # snackbar:
    # swiper_css:
    # swiper_js:
    # twikoo:
    # typeit_js:
    # valine:
    # waline_css:
    # waline_js:
# --------------------------- fin ---------------------------