mycpen

Mycpen

记录学习历程与受益知识
github
telegram
bilibili

01_Hexo-Hexo + Pure Build Blog - Customization

Building a Personal Blog with Hexo#

I. Introduction#

1.1 Hexo#

Hexo is a fast, simple, and efficient blogging framework. Hexo uses Markdown (or other rendering engines) to parse articles and can generate static web pages with beautiful themes in seconds. Hexo Official Website

1.2 Pure Theme#

Hexo theme pure. It's a pure theme for Hexo.

https://blog.cofess.com/


II. References#

Hexo Official Website https://hexo.io/zh-cn/docs/index.html

Pure Project Address https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md

Setup & Customization#


III. Commands#

hexo clean ; hexo g ; hexo d ; hexo s

IV. Comments & Indexing#

Valine Comments https://www.leancloud.cn/

Valine Comments https://www.leancloud.app/ Foreign site, domestic accounts are restricted, the domain may not have been successfully obtained for free, possibly the reason → https://forum.leancloud.cn/t/2022-8/25408

Google Indexing https://search.google.com/search-console

Baidu Indexing https://ziyuan.baidu.com

MD5 Online Encryption https://md5jiami.bmcx.com/ Comments section through ciphertext, identify the blogger's identity


[Article Path]: 
	\source\_posts
[Site Configuration File]: 
	\_config.yml
[Theme Configuration File]: 
	\themes\pure\_config.yml	"About, Personal Introduction, Announcements"
[Friend Links File]: 
	\source\_data\links.yml
[Language]: 
	\themes\pure\languages
[Bottom Left Running Time]: 
	\themes\pure\layout\_common\footer.ejs	"Time, Copyright"
[Comment Role Configuration]: 
	\themes\pure\layout\_script\_comment\valine.ejs
[CSS Styles]:
	\themes\pure\source\css\style.css
[Search Bar Limit]: 
	\themes\pure\source\js\insight.js	"Line 160"

VI. Content Example#

---
title: Test
date: 2022-08-28 00:09:00
updated: 2022-08-28 00:09:01
thumbnail: https://image.cpen.top/image/test.png
tags:
    - Test
category:
    - Test
toc: true
top: true
---
Description<!-- more -->

Article with Multiple Categories#

Multiple Categories

If our requirement is to categorize an article into two or more different categories, the official method is:

categories:
  - [Sports]
  - [Baseball]

Reference Article: Hexo Article with Multiple Categories https://www.jianshu.com/p/4438c417611e


VII. Customization#

7.1 Search Box Index Breakthrough 5#

  1. F12 locate the class selector for the search box as ins-section-header
  2. grep, locate the configuration file as \themes\pure\source\js\insight.js
  3. Ctrl + F, search 5, locate line 160, modify the limit

image-20220830075511578

image-20220830075224471

image-20220830075722865

a tag, change target: '_blank' → '_self'

image-20220830080811356

image-20220830080916410

image-20220830080945424


7.3 Article Directory, Level 1 Title Does Not Jump#

Sometimes it is found that the level 1 title does not jump

Configuration file \node_modules\hexo\lib\plugins\helper\toc.js

Update the \node_modules\hexo\lib\plugins\helper\toc.js file, and it works normally again. It can be inconsistent...

Reference https://hwame.top/ 如何取消文章目录的自动编号

Modify ".\node_modules\hexo-renderer-markdown-it\index.js" level to 1

image-20220906033013691


7.4 Thickening Scroll Bar + Adding Small Arrow#

  • Modify CSS styles, path .\hexo-source\themes\pure\source\css\style.css

    1. Ctlrl + F locate scrollbar;

    2. Increase height to thicken the right scrollbar of the code box;

    3. The right dropdown bar becomes thicker;

    7.4.1 Thickening Code Box

    /*
     * scrollbar
     */
    
    ::-webkit-scrollbar {
      width: 15px;
      height: 14px;					# Increase
      background: transparent;
    }
    

    image-20220901164700329

    7.4.2 Thickening Right Dropdown Bar + Adding Small Arrow

    /*
     * Scrollbar Arrow							
     */
    ::-webkit-scrollbar-button {
        width: 0px;
        height: 4px;
        display: block; 
        background-color: #c3c3c3;
    }
    ::-webkit-scrollbar {
      width: 16px;
      border: 5px solid white;
    
    }
    
    ::-webkit-scrollbar-thumb {
      background-color: #b0b0b0;
      background-clip: padding-box;
      border: 0.05em solid #eeeeee;
    }
    
    ::-webkit-scrollbar-track {
      background-color: #bbbbbb;
    }
    /* Buttons */
    ::-webkit-scrollbar-button:single-button {
      background-color: #bbbbbb;
      display: block;
      border-style: solid;
      height: 13px;
      width: 16px;
    }
    /* Up */
    ::-webkit-scrollbar-button:single-button:vertical:decrement {
      border-width: 0px 8px 8px 8px;
      border-color: transparent transparent #555555 transparent;
    }
    
    ::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
      border-color: transparent transparent #777777 transparent;
    }
    /* Down */
    ::-webkit-scrollbar-button:single-button:vertical:increment {
      border-width: 8px 8px 0 8px;
      border-color: #555555 transparent transparent transparent;
    }
    
    ::-webkit-scrollbar-button:vertical:single-button:increment:hover {
      border-color: #777777 transparent transparent transparent;
    }
    

    image-20220901164914382

Reference Articles

7.5 Adding Hitokoto to Valine Comment Box#

Reference Article

Accidentally saw this article, and then I added this feature myself.

  • Path: .\themes\pure\layout\_script\_comment\valine.ejs;

  • Add before the last </script> tag; c=j request to get a sentence from NetEase Cloud, let's start the net depression;

        fetch('https://v1.hitokoto.cn/?c=j')
        .then(response => response.json())
        .then(data => {
          document.getElementById("veditor").setAttribute("placeholder",data.hitokoto+"__"+data.from);
        })
        .catch(console.error)
    

Modification Method:

  1. Find the corresponding position to add valine in the blog, for example, the Ayer theme is located at hexo\themes\ayer\layout_partial\post\valine.ejs

  2. Add a piece of code inside:

    <script type="text/javascript">
       fetch('https://v1.hitokoto.cn')
        .then(response => response.json())
        .then(data => {
          document.getElementById("veditor").setAttribute("placeholder",data.hitokoto+"__"+data.from);
        })
        .catch(console.error)
    </script>
    
  3. API Interface Description:
    (1) https://v1.hitokoto.cn/ (Randomly selected from 7 categories)
    (2) https://v1.hitokoto.cn/?c=b (Request to get a sentence from the comic category)
    Parameters Description
    a Animation
    b Comics
    c Game
    d Literature
    e Original
    f From the Internet
    g Others
    h Film and Television
    i Poetry
    j NetEase Cloud
    k Philosophy
    l Playful
    Others Processed as animation type
    Multiple categories can be selected, e.g.: ?c=a&c=c

(3) https://v1.hitokoto.cn/?c=f&encode=text (Request to get a sentence from the internet and output in plain text format)

  1. Returned Format Description
    Returned Parameter Name Description
    id Hitokoto Identifier
    hitokoto Hitokoto Text. Encoding method unicode. Use utf-8.
    type Type
    from Source of Hitokoto
    from_who Author of Hitokoto
    creator Adder
    creator_uid Adder User Identifier
    reviewer Reviewer Identifier
    uuid Hitokoto Unique Identifier; can link to https://hitokoto.cn?uuid=[uuid] to view complete information of this hitokoto
    commit_from Submission Method
    created_at Add Time
    length Sentence Length
    For example: the returned data, get the sentence text through data.hitokoto

Author: Justlovesmile
Link: https://blog.justlovesmile.top/posts/27831.html
Source: Justlovesmile's BLOG
Copyright belongs to the author. For commercial reproduction, please contact the author for authorization, for non-commercial reproduction, please indicate the source.

PS: This blogger's blog is really beautiful~~

7.6 Left Archive, Category Default to Collapsed#

  • The default is expanded

image-20220901203849607

image-20220901203907981

  • Modify the following files to change to collapsed state. As shown
    • style="height: 0px" should not need to be written, the collapsed state is default to 0 ~~

.\themes\pure\layout\categories.ejs

.\themes\pure\layout\_partial\archive.ejs

image-20220901203746673

image-20220901203807739


VIII. Unresolved Small Needs#

  1. (Resolved, #7.3) Level 1 directory, right navigation bar sometimes fails to jump;

  2. Valine comment system, the comments below are not displaying @ information after being @, while others are successful;

    Mine

    image-20220901171817579

    Other bloggers

    image-20220901171912131

  3. When quoting, using # will be mistakenly regarded as a level 1 title by the navigation directory;

    image-20220901172133945

    image-20220901172316157

  4. (Resolved) Static files generated in the /public directory are all compressed, I saw that others were not compressed, unclear reason. Because this configuration https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md Blog Optimization compressed the files

    image-20220901175404486

  5. (Resolved) No anchor points on the left side of the article's level 1, level 2... titles

    Ideal effect picture

    image-20220906034109271

    It seems to be an environment configuration issue. When I push static files using a virtual machine, it shows; when I push using a real Windows machine, there are no anchor points, reinstalling git also does not show (may not be git's problem)...

    Because the static files were compressed, all commented out hexo-neat configuration.
    Reference
    https://github.com/cofess/hexo-theme-pure#hexo-neat
    https://github.com/rozbo/hexo-neat#options

Not a big deal, I usually write the article title as the level 1 title; the comments section is just a decoration; the static files being compressed may make others think I did it on purpose, hey~~

In conclusion: Customization should be moderate, too time-consuming without improvement, better to watch a few more front-end videos and write a few more articles...

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.