Eastwatch

Listen to the rhythm of the falling rain.

0%

Write personal diary in Hexo blog

Create diary menu item in sidebar

  1. Run hexo new page diary. This will create a diary folder under ./source

  2. You can modify ./source/diary/index.md. It is this file that will be rendered when you click the diary menu item in the sidebar.

  3. Modify ./themes/next/_config.yml to show the diary item in the sidebar:

    1
    2
    3
    menu:
    # add the following line!
    Diary: /diary/ || fa fa-book

    Note: "book" is the icon name in the font-awesome website. You can choose whatever icon you like and use that icon's name.

    The effect is like this:

Protect your diary using password

  1. run npm install --save hexo-blog-encrypt to install plugin

  2. add the following code in ./_config.yml:

    1
    2
    3
    4
    encrypt:
    enable: true
    default_abstract: blabla
    default_message: blabla
  3. Add password and message fields at the header(Front-matter) of ./source/diary/index.md, like this:

    1
    2
    3
    4
    5
    6
    ---
    title: My Diary
    comments: false
    password: psw
    message: Oops, you need a password
    ---

    Note: If you don't provide the "message" field, it will be replaced by the default message you set.

    Then when you click the diary item in the sidebar, the page will show:

Generate diaries

  1. Create folders like this: ./source/_posts/diary/2021

  2. Create ./scaffolds/diary.md, which will be your diary template: (you can also make it nicer)

    1
    2
    3
    4
    5
    ---
    title: {{title}}
    date: {{data}}
    description:
    ---
  3. Create your diary using the template you created: hexo new diary --path "diaries/2021/0825__" "08/25 diary"

  4. Modify ./source/diary/index.md to link the new file you created:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    ---
    title: My Diary
    comments: false
    password: psw
    message: Oops, you need a password
    ---

    - 2021
    - [08-25](/diary/2021/08-25/)

    Then when you enter the right password, the page will show:

  1. modify./scaffolds/diary.md, add a field in the front-matter: notshow: true

  2. modify ./themes/next/layout/index.swig:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    {%- for post in page.posts.toArray() %}
    {{ partial('_macro/post.swig', {post: post, is_index: true}) }}
    {%- endfor %}

    # change to:

    {%- for post in page.posts.toArray() %}
    {% if post.notshow != true %}
    {{ partial('_macro/post.swig', {post: post, is_index: true}) }}
    {% endif %}
    {%- endfor %}

All the posts with notshow: true in their front-matters will be hidden in the home page (only in the home page).

Hide diaries everywhere

Afte testing, I found the solution above only let the diaries visually disappear in the home page. But they can also appear in the achieve, category, sitemap or being indexed by google. I personally want my diaries only visible to those who has the right password. After searching for a while, I found a plugin which can conveniently hide diaries everywhere. You can see the installation and configuration in here: https://github.com/printempw/hexo-hide-posts.

Hide means your posts will not come up in article lists (homepage, archive, category, tag, feed, sitemap, whatever), or search results either (by telling search engines not to index these pages with a "noindex" meta tag). Only those who know the link can view the post, and you can share the link with anyone. ---- From hexo-hide-posts

After installation and configuration, just modify./scaffolds/diary.md, add a field in the front-matter: hidden: true.