和光同尘,与时舒卷

Hexo Seo 搜索引擎优化

2024.06.26

SEO,全称Serch Engine Optimization,搜索引擎优化

目的


  • 规范内容
  • 便于抓取
  • 提高收录
  • 利于分享

优化


  • 配置robots.txt

该文件位于根目录,用于控制抓取内容,哪些允许,哪些不允许

# welcome to : your site
User-agent: *
Allow: /
Allow: /archives/
Allow: /categories/
Allow: /about/

Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /lib/
Sitemap: https://your_site_address/sitemap.xml
  • 文章结构优化

hexo生成的文章是sitename/year/mounth/day/title 四层的结构,不利于抓取

修改permalink为sitename/title的两层结构

添加 html 后缀,利于搜索引擎从 url 后缀判断是 html 页面 将 trailing_index 设置为 false 这样生成的目录结构为yoursite/category/title.html 如果不设置为 false, 则为 yoursite/category/title/index.html

url: your site 
permalink: :title.html
permalink_defaults:
pretty_urls:
  trailing_index: false # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks
  • 页面内容优化

hexo生成的页面有大量空白,不利于抓取

npm install hexo-neat --save

hexo根目录下配置config.yml

neat_enable: true
neat_html:
  enable: true
  exclude:
neat_css:
  enable: true
  exclude:
    - "**/*.min.css"
neat_js:
  enable: true
  mangle: true
  output:
  compress:
  exclude:
    - "**/*.min.js"
    - "**/index.js"
  • 配置主动推送

npm install --save hexo-submit-urls-to-search-engine

Bing Webmaster Tools-设置-API访问凭证

Baidu资源平台-站点管理-资源提交-普通收录-API提交-token

hexo根目录下配置config.yml

hexo_submit_urls_to_search_engine:
  submit_condition: count # count/period The submitted condition, only supports count now
  count: 20 ## Submit the latest 10 links
  period: 900 #A period of time, in seconds, the update time of the article is away from the running time of the plugin. Within this period of time, the link will be submitted
  google: 0 #  1/0->on/off   Submit to Google
  bing: 1 #Submit to bing
  baidu: 1 #Submit to baidu
  txt_path: submit_urls.txt ## The address of the text document, the link to be pushed will be saved in this text document
  baidu_host: https://yoursite ## Domain name registered in Baidu webmaster platform
  baidu_token: xxxxx ## Please note that this is your secret key, so do not publish the website source code in the public repository!
  bing_host: https://yoursite ## Domain name registered in Bing webmaster platform
  bing_token: xxxxx ## Please note that this is your secret key, so do not publish the website source code in the public repository!
  google_host: https://yoursite ## Domain name registered in Google webmaster platform
  google_key_file: Project.json #Store the json file of the google key in the root directory of the website (same location as the hexo config.yml file), please do not publish the source code of the website in the public warehouse!

配置deploy,添加

deploy:
  - type: cjh_google_url_submitter
  - type: cjh_bing_url_submitter
  - type: cjh_baidu_url_submitter

如果有多个deploy项 要加 “-”并缩进

  • 命名优化

区分.md的文件名和front-matter中文章名称

.md源文件用于生成文章,尽量用英文名,不用使用空格,用“-”代替空格

front-matter中名称,用于显示文章title,用简练的中文