Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Chore(deps-dev): Bump lint-staged from 15.2.9 to 15.2.10
  Feat: 增加内容适配器,根据仓库 README 自动生成文章

# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
Lruihao committed Oct 1, 2024
2 parents 5429df4 + c037f23 commit 551cb59
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 84 deletions.
35 changes: 29 additions & 6 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ disableThemeInject = false
enable = true
sticky = true
showHome = false
# FixIt 0.3.13 | NEW
separator = "/"
capitalize = true

# FixIt 0.3.10 | NEW Post navigation config
# FixIt 0.3.10 | 新增 文章导航配置
Expand Down Expand Up @@ -702,12 +705,6 @@ disableThemeInject = false
# 检查更新
c4u = false

# FixIt Docs config
[planet]
invite = "https://t.zsxq.com/BQcpe" # 正常加入链接:https://t.zsxq.com/CE3GF
promotion_coupon = "https://t.zsxq.com/BQcpe"
renewal_coupon = ""

# Page config
# 文章页面配置
[page]
Expand Down Expand Up @@ -1145,3 +1142,29 @@ disableThemeInject = false
[page.seo.publisher]
name = "Lruihao"
logoUrl = "/images/avatar.png"

# -------------------------------------------------------------------------------------
# Theme Components Configuration | 主题组件配置
# -------------------------------------------------------------------------------------

# Content adapters config for component projects
# https://github.com/hugo-fixit/component-projects
[projectsAdapters]
enable = true
# Whether to show only public repos
onlyPublic = true
# Default categories and collections
categories = ["README"]
collections = ["Components"]
# Ignore repos in the ignore list
ignoreList = [
"hugo-fixit/.tools",
"hugo-fixit/hugo-atom-feed",
"hugo-fixit/component-skeleton",
]

# FixIt Docs config
[planet]
invite = "https://t.zsxq.com/BQcpe" # 正常加入链接:https://t.zsxq.com/CE3GF
promotion_coupon = "https://t.zsxq.com/BQcpe"
renewal_coupon = ""
93 changes: 93 additions & 0 deletions content/en/components/_content.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- /*
* This template is used to create a post for each repo in the data file.
* You must copy it to your project to make it work.
* https://github.com/hugo-fixit/component-projects
* @author Lruihao (https://lruihao.cn)
*/ -}}

{{- $auth := dict "Authorization" "" -}}
{{- with (getenv "HUGO_PARAMS_GHTOKEN") -}}
{{- $auth = dict "Authorization" (printf "token %v" .) -}}
{{- end -}}
{{- $headers := dict "headers" $auth -}}
{{- $projectsAdapters := .Site.Params.projectsAdapters -}}
{{- $data := index .Site.Data (printf "projects.%v" .Site.Language.Lang) | default .Site.Data.projects -}}

{{- /* Loop through the data and create a post for each repo */ -}}
{{- range $group := $data -}}
{{- $allowed := $projectsAdapters.enable | and (ne $group.contentAdapters false) -}}
{{- if not $allowed -}}
{{- break -}}
{{- end -}}
{{- range $repo := $group.repos -}}
{{- /* Ignore repos in the ignore list */ -}}
{{- if in $projectsAdapters.ignoreList $repo -}}
{{- continue -}}
{{- end -}}
{{- $projectsAdapters.ignoreList -}}
{{- $repoAPI := printf "https://api.github.com/repos/%v" $repo -}}
{{- $repoInfo := partial "function/get-remote-json" (dict "URL" $repoAPI "OPTIONS" $headers ) -}}
{{- $readmeAPI := printf "https://api.github.com/repos/%v/contents/README.%v.md" $repo $.Site.Language.Lang -}}
{{- $readme := partial "function/get-remote-json" (dict "URL" $readmeAPI "OPTIONS" $headers ) -}}

{{- /* Get the default README if the multi-language README is not available */ -}}
{{- if not $readme -}}
{{- $readmeAPI = printf "https://api.github.com/repos/%v/contents/README.md" $repo -}}
{{- $readme = partial "function/get-remote-json" (dict "URL" $readmeAPI "OPTIONS" $headers ) -}}
{{- end -}}

{{- /* Skip if the repo info or README is not available */ -}}
{{- if
(not $repoInfo) | or
(not $readme) | or
(and $projectsAdapters.onlyPublic (eq $repoInfo.visibility "private"))
-}}
{{- warnidf "warning-projects-adapter" "Repo %v is not available or is private." $repo -}}
{{- continue -}}
{{- end -}}

{{- /* Post dates from repo info */ -}}
{{- $dates := dict
"date" (time.AsTime $repoInfo.created_at)
"lastmod" (time.AsTime $repoInfo.updated_at)
-}}
{{- /* Post params from repo info (equivalent to the front matter of posts) */ -}}
{{- $params := dict
"fromAdapters" "projects"
"categories" $projectsAdapters.categories
"collections" $projectsAdapters.collections
"tags" $repoInfo.topics
"lightgallery" true
"breadcrumb" (dict "capitalize" false)
"toc" (dict "ordered" false)
"subtitle" ($repoInfo.homepage | default $repoInfo.html_url)
"sourceURL" (add $readme.html_url "?plain=1")
"editURL" (replace $readme.html_url "/blob/" "/edit/" )
"LinkToReport" false
-}}
{{- /* Post content from repo README */ -}}
{{- $markdown := $readme.content | base64Decode -}}
{{- /* Convert Hugo shortcodes to markdown plain text */ -}}
{{- $markdown = replace $markdown "{{<" "{{?{}<" -}}
{{- /* Convert relative links to absolute links in the README content */ -}}
{{- $replacement := printf "$1[$2](%v$4)" (printf "https://raw.githubusercontent.com/%v/refs/heads/%v/$3" $repoInfo.full_name $repoInfo.default_branch) -}}
{{- /* Oops! Lookahead regular lookup is not supported in Golang, e.g `(?!http)` */ -}}
{{- $markdown = replaceRE `([!]?)\[(.*?)\]\((/.*).*?(\s+".*?")?\)` $replacement $markdown -}}
{{- $content := dict
"mediaType" "text/markdown"
"value" $markdown
-}}
{{- /* Create a post page */ -}}
{{- $page := dict
"title" $repoInfo.description
"linkTitle" $repoInfo.full_name
"path" $repoInfo.full_name
"dates" $dates
"description" (printf "%s: %s" (replace $repoInfo.full_name "-" " ") $repoInfo.description)
"content" $content
"params" $params
"type" "posts"
-}}
{{- $.AddPage $page -}}
{{- end -}}
{{- end -}}
2 changes: 0 additions & 2 deletions content/en/components/dev-component/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ or
The presentation effect is as follows:
```
{{< caniuse "css-grid" >}}
```
## References
Expand Down
10 changes: 10 additions & 0 deletions content/en/documentation/getting-started/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ subtitle
enable = false
sticky = false
showHome = false
separator = "/"
capitalize = false
```

enable
Expand All @@ -589,6 +591,14 @@ sticky
showHome
: `bool` Whether to show the home link in the breadcrumb. Default is `false`.

separator
: {{< version 0.3.13 >}}\
`string` The separator of the breadcrumb. Default is `/`.

capitalize
: {{< version 0.3.13 >}}\
`bool` Whether to capitalize the breadcrumb. Default is `false`.

### navigation

{{< version 0.3.10 >}}
Expand Down
3 changes: 3 additions & 0 deletions content/zh-cn/collections/components/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: 主题组件
---
93 changes: 93 additions & 0 deletions content/zh-cn/components/_content.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- /*
* This template is used to create a post for each repo in the data file.
* You must copy it to your project to make it work.
* https://github.com/hugo-fixit/component-projects
* @author Lruihao (https://lruihao.cn)
*/ -}}

{{- $auth := dict "Authorization" "" -}}
{{- with (getenv "HUGO_PARAMS_GHTOKEN") -}}
{{- $auth = dict "Authorization" (printf "token %v" .) -}}
{{- end -}}
{{- $headers := dict "headers" $auth -}}
{{- $projectsAdapters := .Site.Params.projectsAdapters -}}
{{- $data := index .Site.Data (printf "projects.%v" .Site.Language.Lang) | default .Site.Data.projects -}}

{{- /* Loop through the data and create a post for each repo */ -}}
{{- range $group := $data -}}
{{- $allowed := $projectsAdapters.enable | and (ne $group.contentAdapters false) -}}
{{- if not $allowed -}}
{{- break -}}
{{- end -}}
{{- range $repo := $group.repos -}}
{{- /* Ignore repos in the ignore list */ -}}
{{- if in $projectsAdapters.ignoreList $repo -}}
{{- continue -}}
{{- end -}}
{{- $projectsAdapters.ignoreList -}}
{{- $repoAPI := printf "https://api.github.com/repos/%v" $repo -}}
{{- $repoInfo := partial "function/get-remote-json" (dict "URL" $repoAPI "OPTIONS" $headers ) -}}
{{- $readmeAPI := printf "https://api.github.com/repos/%v/contents/README.%v.md" $repo $.Site.Language.Lang -}}
{{- $readme := partial "function/get-remote-json" (dict "URL" $readmeAPI "OPTIONS" $headers ) -}}

{{- /* Get the default README if the multi-language README is not available */ -}}
{{- if not $readme -}}
{{- $readmeAPI = printf "https://api.github.com/repos/%v/contents/README.md" $repo -}}
{{- $readme = partial "function/get-remote-json" (dict "URL" $readmeAPI "OPTIONS" $headers ) -}}
{{- end -}}

{{- /* Skip if the repo info or README is not available */ -}}
{{- if
(not $repoInfo) | or
(not $readme) | or
(and $projectsAdapters.onlyPublic (eq $repoInfo.visibility "private"))
-}}
{{- warnidf "warning-projects-adapter" "Repo %v is not available or is private." $repo -}}
{{- continue -}}
{{- end -}}

{{- /* Post dates from repo info */ -}}
{{- $dates := dict
"date" (time.AsTime $repoInfo.created_at)
"lastmod" (time.AsTime $repoInfo.updated_at)
-}}
{{- /* Post params from repo info (equivalent to the front matter of posts) */ -}}
{{- $params := dict
"fromAdapters" "projects"
"categories" $projectsAdapters.categories
"collections" $projectsAdapters.collections
"tags" $repoInfo.topics
"lightgallery" true
"breadcrumb" (dict "capitalize" false)
"toc" (dict "ordered" false)
"subtitle" ($repoInfo.homepage | default $repoInfo.html_url)
"sourceURL" (add $readme.html_url "?plain=1")
"editURL" (replace $readme.html_url "/blob/" "/edit/" )
"LinkToReport" false
-}}
{{- /* Post content from repo README */ -}}
{{- $markdown := $readme.content | base64Decode -}}
{{- /* Convert Hugo shortcodes to markdown plain text */ -}}
{{- $markdown = replace $markdown "{{<" "{{?{}<" -}}
{{- /* Convert relative links to absolute links in the README content */ -}}
{{- $replacement := printf "$1[$2](%v$4)" (printf "https://raw.githubusercontent.com/%v/refs/heads/%v/$3" $repoInfo.full_name $repoInfo.default_branch) -}}
{{- /* Oops! Lookahead regular lookup is not supported in Golang, e.g `(?!http)` */ -}}
{{- $markdown = replaceRE `([!]?)\[(.*?)\]\((/.*).*?(\s+".*?")?\)` $replacement $markdown -}}
{{- $content := dict
"mediaType" "text/markdown"
"value" $markdown
-}}
{{- /* Create a post page */ -}}
{{- $page := dict
"title" $repoInfo.description
"linkTitle" $repoInfo.full_name
"path" $repoInfo.full_name
"dates" $dates
"description" (printf "%s: %s" (replace $repoInfo.full_name "-" " ") $repoInfo.description)
"content" $content
"params" $params
"type" "posts"
-}}
{{- $.AddPage $page -}}
{{- end -}}
{{- end -}}
18 changes: 18 additions & 0 deletions content/zh-cn/documentation/getting-started/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,16 @@ subtitle

`map` 面包屑导航配置。

```toml
[params]
[params.breadcrumb]
enable = false
sticky = false
showHome = false
separator = "/"
capitalize = false
```

enable
: `bool` 是否启用面包屑导航。

Expand All @@ -583,6 +593,14 @@ sticky
showHome
: `bool` 是否显示主页链接。

separator
: {{< version 0.3.13 >}}\
`string` 分隔符,默认:`/`

capitalize
: {{< version 0.3.13 >}}\
`bool` 是否大写面包屑导航。

### navigation

{{< version 0.3.10 >}}
Expand Down
1 change: 1 addition & 0 deletions data/projects.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
- hugo-fixit/.tools
- title: 👾 Third party
description: "Welcome to contribute [PR :(fa-solid fa-code-branch fa-fw):](https://github.com/hugo-fixit/docs/edit/dev/data/projects.en.yml) your theme components."
contentAdapters: false
repos:
- fixit-theme/hugo-shortcode-plugins-live2d
1 change: 1 addition & 0 deletions data/projects.zh-cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
- hugo-fixit/.tools
- title: 👾 第三方
description: "欢迎大家投稿 [PR :(fa-solid fa-code-branch fa-fw):](https://github.com/hugo-fixit/docs/edit/dev/data/projects.zh-cn.yml) 你开发的主题组件。"
contentAdapters: false
repos:
- fixit-theme/hugo-shortcode-plugins-live2d
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/hugo-fixit/docs
go 1.20

require (
github.com/hugo-fixit/FixIt v0.3.12 // indirect
github.com/hugo-fixit/component-projects v1.1.4-0.20240930061452-3e28588292d5 // indirect
github.com/hugo-fixit/FixIt v0.3.13-0.20241001115042-e9edbba217d9 // indirect
github.com/hugo-fixit/component-projects v1.2.0 // indirect
github.com/hugo-fixit/shortcode-caniuse v1.1.3 // indirect
github.com/hugo-fixit/shortcode-rewards v1.0.4 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/hugo-fixit/FixIt v0.3.12 h1:0XmgKKGafFj7Mb/aecfnLcXMAOUuVLyMKEYyNR0IAt4=
github.com/hugo-fixit/FixIt v0.3.12/go.mod h1:3XIRedrqakO7/a4ZnhE46haMRF8HgsT0N0B5j5D2iRU=
github.com/hugo-fixit/component-projects v1.1.4-0.20240930061452-3e28588292d5 h1:G65Wq/VLIsKTaiQ6o3dMkUSXYwk/h1JvIGInqg1e4CY=
github.com/hugo-fixit/component-projects v1.1.4-0.20240930061452-3e28588292d5/go.mod h1:nXW0R37REwpfwUD1I4RtB5QW71vw66nRyB9uEpYxr+c=
github.com/hugo-fixit/FixIt v0.3.13-0.20241001115042-e9edbba217d9 h1:0TXHvCynxnJRIaAnJ5oIcj0AHxKLQ3+WlSjNSsJkejc=
github.com/hugo-fixit/FixIt v0.3.13-0.20241001115042-e9edbba217d9/go.mod h1:3XIRedrqakO7/a4ZnhE46haMRF8HgsT0N0B5j5D2iRU=
github.com/hugo-fixit/component-projects v1.2.0 h1:CxAjX/tUsgbn9NivUnDqE4ocbawKGh8Bmb4PnTHMEjw=
github.com/hugo-fixit/component-projects v1.2.0/go.mod h1:nXW0R37REwpfwUD1I4RtB5QW71vw66nRyB9uEpYxr+c=
github.com/hugo-fixit/shortcode-caniuse v1.1.3 h1:U1YBJz5SI/d1BBQhHcD0eVgJdCcpzK2usSizPiu+a4w=
github.com/hugo-fixit/shortcode-caniuse v1.1.3/go.mod h1:RoPLFt+7uLui5rjvkC/qFGeo4nly5AzzwIID9SoDKNc=
github.com/hugo-fixit/shortcode-rewards v1.0.4 h1:62qCmcGvAJf+qa+8ofRX6jwMUXo6Q4+PQvlOtu0ZGBA=
Expand Down
Loading

0 comments on commit 551cb59

Please sign in to comment.