XPoet / hexo-theme-keep

:rainbow: A simple and light theme for Hexo. It makes you more focused on writing.
https://xpoet.cn
GNU Affero General Public License v3.0
1.3k stars 176 forks source link

如何自定义首页中的文章摘要? #83

Closed brtang181 closed 3 years ago

brtang181 commented 3 years ago

首页中会自动生成文章摘要, 但因为没有分行, 有时观感不是很好, 请问能否自定义摘要?

XPoet commented 3 years ago

Hexo 自带自定义截取文章摘要的功能。

使用截取符 <!-- more --> 截取的摘要,会以 Markdown 格式显示。

例如这篇文章的摘要:

---
title: Keep 主题使用指南
date: 2020-04-07 21:55:14
tags: [Hexo, Keep]
categories: [Keep]
sticky: 9999
---

如你所见,Keep 主题界面设计十分简洁、大气,同时也功能齐全、不失优雅,这正是 Keep 主题的开发理念。也曾尝试过花里胡哨,发现不仅配置繁琐、容易审美疲劳,而且背驰了写博客的初衷,记录生活、展示文字,应该才是搭建博客网站的最终追求,为此 Keep 主题应运而生。简约轻快、化繁为简、配置简单、突出内容、长期维护,如果你也喜欢或认可这些特点,一起来探索吧~

## 文档 | Documents

在使用 Keep 主题过程中,请仔细阅读[官方使用文档](https://keep-docs.xpoet.cn/),绝大部分问题,都能在文档里找到参考。

- [Keep 主题 - 官方文档](https://keep-docs.xpoet.cn/)

- [Keep 主题 - 快速开始](https://keep-docs.xpoet.cn/usage-tutorial/quick-start.html)

- [Keep 主题 - 配置指南](https://keep-docs.xpoet.cn/usage-tutorial/configuration-guide.html)

- [Keep 主题 - 进阶设置](https://keep-docs.xpoet.cn/usage-tutorial/advanced.html)

<!-- more -->
......
......

首页摘要效果

image

XPoet commented 3 years ago

如果在文章中未添加 <!-- more --> 截取符,那么就会自动截取无格式的摘要,文章前180个字符

NeeoMacLynch commented 3 years ago

您好,我再文章中添加了截取符,但是在首页上仍是“自动截取无格式的摘要,文章前180个字符”

XPoet commented 3 years ago

@NeeoMacLynch

1、文章截取符的位置截图我看看 2、清空下浏览器缓存再刷新看看

NeeoMacLynch commented 3 years ago

@XPoet image

清除缓存后仍然不行,另外使用反引号块实现代码高亮也不行,markdown 预览上有高亮效果,但是到 blog 上就没有显示了

XPoet commented 3 years ago

Keep 主题这些功能 都是正常可用的。是你配置问题: 你的 Hexo 配置文件发一下 文章的 md 文件也发一下

便于我排查

NeeoMacLynch commented 3 years ago

@XPoet 已通过邮件的方式发送,谢谢

XPoet commented 3 years ago

@NeeoMacLynch 没有收到你邮件! 我邮箱:i@xpoet.cn

NeeoMacLynch commented 3 years ago

@XPoet 已重新发送,谢谢!

XPoet commented 3 years ago

@NeeoMacLynch 还是没收到你的邮件,垃圾箱也没有,你检查一下是否成功发送,要么直接发到 Issue

NeeoMacLynch commented 3 years ago

@XPoet Hexo配置源码

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Lynch's Blog
subtitle: Lynch's Blog
description: Work-Life balance
keywords:
author: Lynch Lee
language: zh-CN
timezone: ''

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: https://neeomaclynch.github.io/
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
  trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
  enable: true # Open external links in new tab
  field: site # Apply to the whole site
  exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: false
highlight:
  enable: true
  auto_detect: false
  line_number: true
  tab_replace: '  '
  wrap: true
  hljs: false
prismjs:
  enable: false

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: keep

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: git
  repo:
    github: https://github.com/NeeoMacLynch/NeeoMacLynch.github.io.git
  branch: gh-pages

# Search
## See: https://github.com/theme-next/hexo-generator-searchdb
search:
  path: search.json
  field: post
  content: true
  format: striptags

# Minifier
  all_minifier: false

mathjax:
  tags: none               # or 'ams' or 'all'
  single_dollars: true     # enable single dollar signs as in-line math delimiters
  cjk_width: 0.9           # relative CJK char width
  normal_width: 0.6        # relative normal (monospace) width
  append_css: true         # add CSS to every page
  every_page: false        # if true, every page will be rendered by mathjax regardless the `mathjax` setting in Front-matter of each article

主题配置源码,使用平滑升级的方式

# ---------------------------------------------------------------------------------------
#  Your basic info
# ---------------------------------------------------------------------------------------
base_info:
  title: Lynch's Blog
  author: Lynch Lee
  url: https://neeomaclynch.github.io/

# ---------------------------------------------------------------------------------------
# Theme style settings
# ---------------------------------------------------------------------------------------
style:
  # Theme primary color
  primary_color: '#0066CC'

  # Avatar (You can use local image or image external link)
  avatar: /images/avatar.png

  # Favicon (You can use local image or image external link)
  favicon: /images/favicon.ico

  # Article image align position, value: left | center
  article_img_align: center

  # Left side width
  left_side_width: 260px

  # Content area max width
  content_max_width: 920px

  # Mouse hover
  hover:
    shadow: true   # shadow effect when the mouse hover
    scale: false    # scale effect when the mouse hover

  # First screen
  first_screen:
    enable: true
    background_img: /images/bg.svg   # You can use local image or image external link
    description: Work-Life balance.

  # Scroll style settings
  scroll:
    progress_bar:
      enable: false
    percent:
      enable: false

# ---------------------------------------------------------------------------------------
# Social contact link
# ---------------------------------------------------------------------------------------
social_contact:
  enable: true
  links:
    github: https://github.com/NeeoMacLynch # your GitHub URL
    weixin:          # your WeChat QR-Code URL
    qq:              # your QQ QR-Code URL
    weibo:           # your WeiBo URL
    zhihu:           # your ZhiHu URL
    twitter:         # your twitter URL
    facebook:        # your facebook URL
    email: qqdblue9533@live.com # your email

# ---------------------------------------------------------------------------------------
# Navigation menu
# ---------------------------------------------------------------------------------------
menu:
  Home: /
  Archives: /archives
  Categories: /categories
  Tags: /tags
  # Links: /links
  About: /about
  # Changelog: /changelog
  # ......

# ---------------------------------------------------------------------------------------
# Home page article block display settings
# ---------------------------------------------------------------------------------------
home_article:
  category:
    enable: false     # show category in home page article block
    limit: 3          # max number of categories shown in home page article block
  tag:
    enable: false     # show tags in home page article block
    limit: 5          # max number of tags shown in home page article block

# ---------------------------------------------------------------------------------------
# Post page Settings
# ---------------------------------------------------------------------------------------
post:
  # Post word count
  # Dependencies: hexo-wordcount (npm install hexo-wordcount)
  # See: https://github.com/willin/hexo-wordcount
  word_count:
    enable: true
    wordcount: true  # word count, one article
    min2read: true   # time to read, one article

  # Author label
  author_label:
    enable: true
    auto: false  # if true, show Lv1, Lv2, Lv3... , If false, show custom label
    # label array item can be one or more
    custom_label_list: [ "BIG_BOSS" ]

# ---------------------------------------------------------------------------------------
# Code copy
# ---------------------------------------------------------------------------------------
code_copy:
  enable: true
  style: mac        # values: default | mac

# ---------------------------------------------------------------------------------------
# Table of Contents in the Sidebar
# ---------------------------------------------------------------------------------------
toc:
  enable: true

  # Automatically add list number to toc.
  number: true

  # If true, all level of TOC in a post will be displayed, rather than the activated part of it.
  expand_all: false

  # If true, open TOC every time when you enter the article page
  init_open: false

# ---------------------------------------------------------------------------------------
# Post copyright info
# ---------------------------------------------------------------------------------------
copyright_info:
  enable: true

# ---------------------------------------------------------------------------------------
# Website count
# ---------------------------------------------------------------------------------------
website_count:
  # busuanzi
  # See: http://ibruce.info/2015/04/04/busuanzi/
  busuanzi_count:
    enable: true
    site_uv: true
    site_pv: true
    page_pv: true

# ---------------------------------------------------------------------------------------
# Local Search
# Dependencies: hexo-generator-searchdb
# See: https://github.com/theme-next/hexo-generator-searchdb
# ---------------------------------------------------------------------------------------
local_search:
  enable: true
  preload: false     # Preload the search data when the page loads

# ---------------------------------------------------------------------------------------
# Comment plugin
# ---------------------------------------------------------------------------------------
comment:
  enable: true
  use: gitalk  # values: valine | gitalk | twikoo

  # Valine
  # See: https://github.com/xCss/Valine
  valine:
    appid:                # your leancloud application appid
    appkey:               # your leancloud application appkey
    placeholder:          # your placeholder

  # Gitalk
  # See: https://github.com/gitalk/gitalk
  gitalk:
    github_id: NeeoMacLynch # GitHub repo owner
    repository: gitalk # Repository name to store issues
    client_id:  # GitHub Application Client ID
    client_secret:  # GitHub Application Client Secret

  # Twikoo
  # See: https://github.com/imaegoo/twikoo
  twikoo:
    env_id:                # Tencent Cloud environment id
    region:                # environment region. If select Guangzhou, fill in "ap-guangzhou".

# ---------------------------------------------------------------------------------------
# RSS
# Dependencies: hexo-generator-feed
# See: https://github.com/hexojs/hexo-generator-feed
# ---------------------------------------------------------------------------------------
rss:
  enable: false

# ---------------------------------------------------------------------------------------
# Lazyload image
# ---------------------------------------------------------------------------------------
lazyload:
  enable: true

# ---------------------------------------------------------------------------------------
# CDN
# ---------------------------------------------------------------------------------------
cdn:
  enable: true

# ---------------------------------------------------------------------------------------
# PJAX
# ---------------------------------------------------------------------------------------
pjax:
  enable: true

# ---------------------------------------------------------------------------------------
# Footer settings
# ---------------------------------------------------------------------------------------
footer:
  since: 2021      # the starting year of your website, Can be null
  icp:             # ICP record number of your website, Can be null

# ---------------------------------------------------------------------------------------
# Keep version (Please don't modify)
# ---------------------------------------------------------------------------------------
version: 3.4.2

文章源码

---
title: Git 使用代理
date: 2021-04-21 14:39:55
comment: true
categories: 
    - 技术
tags: 
    - Git
    - 代理
---

多亏了伟大的防火墙,Git push 一直都不太稳定,如果出现 `Failed to connect to github.com port 443: Timed out` 超时报错,一般通过设置代理或者取消代理并再次 push 以尝试是否能绕过长城,具体操作如下:

<!--more-->

### 查看当前代理

```Bash
git config --global http.proxy
git config --global https.proxy
XPoet commented 3 years ago

@NeeoMacLynch

我用你的配置文件来测试,可以截取文章摘要呀 image

你重新初始一个 Hexo项目,再看看

NeeoMacLynch commented 3 years ago

@XPoet 重新创建后解决啦,感谢

lamkuan commented 3 months ago

一定要重新創建一個項目嗎。。。我也有一樣的問題。