二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rnacher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Vue
  • Shell
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
  • 分类
  • 标签
  • 归档
    • 友链
    • 导航
    • 打赏
    • json2go (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
开往 (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rnacher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Vue
  • Shell
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
  • 分类
  • 标签
  • 归档
    • 友链
    • 导航
    • 打赏
    • json2go (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
开往 (opens new window)
GitHub (opens new window)
  • 最佳实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • Prometheus

  • Grafana

  • CentOS

  • Supervisord

  • Systemd

  • Docker

  • Docker-Compose

  • Rancher

  • Ansible

  • OpenLdap

  • GitLab

  • GitHub

    • 利用GitHub Actions自动为README添加TOC目录
    • 分享我的开源项目Thank-Mirror
  • Etcd

  • Consul

  • RabbitMQ

  • Kafka

  • Mysql

  • MongoDB

  • OpenVPN

  • Kvm

  • VMware

  • 配置文件详解

  • Other

  • 运维观止
  • GitHub
二丫讲梵
2022-05-08

利用GitHub Actions自动为README添加TOC目录原创

GitHub的Markdown目前不支持直接[TOC]渲染文章的目录,有些README则需要这样的效果,可以借助外部工具进行生成,也可以借助 GitHub Actions 自动生成,本文就介绍这种方式。

所用Actions:TOC Generator (opens new window)

使用配置其实非常简单,基本上阅读完官方介绍文档就可以上手使用了,这里说一两个需要注意的地方。

首先需要在将要生成目录的文件内,指定目录生成位置,e.g. README.md,在要生成的地方添加如下内容:

<!-- START doctoc -->
<!-- END doctoc -->
1
2

项目运行之后,会将目录添加在如上两段注释的中间。

然后添加Actions配置文件,e.g. .github/workflows/toc.yml:

on: push
name: TOC Generator
jobs:
  generateTOC:
    name: TOC Generator
    runs-on: ubuntu-latest
    steps:
      - uses: technote-space/toc-generator@v4
1
2
3
4
5
6
7
8

接着需要调整下项目的Actions权限,在GitHub上点击settings--> actions --> General --> Workflow permissions --> 选择 Read and write permissions。

配置调整完成之后,就可以push项目看效果了,当然这里也可以通过GitHub_Token的方式认证,就不赘述了。

配置列表:

name description default required e.g.
TARGET_PATHS Target file path. (Comma separated, Detail) README*.md true README*.md,CHANGELOG.md, .
TOC_TITLE TOC Title **Table of Contents** ''
MAX_HEADER_LEVEL Maximum heading level. (Detail) 3
CUSTOM_MODE Whether it is custom mode(Generated Example) false true
CUSTOM_TEMPLATE Custom template for custom mode <p align="center">${ITEMS}</p>
ITEM_TEMPLATE Item template for custom mode <a href="${LINK}">${TEXT}</a>
SEPARATOR Separator for custom mode <span>|</span>
FOLDING Whether to make TOC foldable false true
COMMIT_MESSAGE Commit message chore(docs): update TOC true docs: update TOC
COMMIT_NAME Git commit name ${github.actor}
COMMIT_EMAIL Git commit email ${github.actor}@users.noreply.github.com
CREATE_PR Whether to create PullRequest false true
CHECK_ONLY_DEFAULT_BRANCH Whether to check only default branch false true
PR_BRANCH_PREFIX PullRequest branch prefix toc-generator/ true
PR_BRANCH_NAME PullRequest branch name Context variables update-toc-${PR_ID} true toc-${PR_NUMBER}
PR_TITLE PullRequest title Context variables chore(docs): update TOC (${PR_MERGE_REF}) true docs: update TOC
PR_BODY PullRequest body Context PR variables action.yml true
PR_COMMENT_BODY PullRequest body for comment Context PR variables action.yml
PR_CLOSE_MESSAGE Message body when closing PullRequest This PR has been closed because it is no longer needed.
TARGET_BRANCH_PREFIX Filter by branch name release/
INCLUDE_LABELS Labels used to check if the PullRequest has it Label1, Label2
OPENING_COMMENT Opening comment (for other than DocToc) <!-- toc
CLOSING_COMMENT Closing comment (for other than DocToc) <!-- tocstop
GITHUB_TOKEN Access token ${{github.token}} true ${{secrets.ACCESS_TOKEN}}

可根据自己的实际需求以及情况进行配置!

上次更新: 2022/05/09, 23:42:59

← git配置github与gitlab推送时指定不同用户与邮箱 分享我的开源项目Thank-Mirror→

最近更新
01
置顶文章汇总 原创
05-23
02
Jenkins基于Share Library共享库的最佳实践探索 原创
05-22
03
Debian系统中执行shell报错unexpected operator 原创
05-21
更多文章>
Theme by Vdoing | Copyright © 2017-2022 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式