Skip to content

Commit

Permalink
using partial to group replaceRE functions
Browse files Browse the repository at this point in the history
  • Loading branch information
flovntp committed Jan 31, 2025
1 parent 911a53d commit fc556ae
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 211 deletions.
2 changes: 1 addition & 1 deletion sites/upsun/config/_default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ outputFormats:
isPlainText: true
permalinkable: true
markdown:
mediaType: "text/plain"
mediaType: "text/markdown"
isPlainText: true
permalinkable: true
baseName: index
Expand Down
53 changes: 1 addition & 52 deletions themes/psh-docs/layouts/_default/home.llms-full.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
{{- $pages := .Site.RegularPages -}}
{{- $upsunUrl := "https://docs.upsun.com" -}}
{{- range $pages -}}
{{- if .Params.title }}# {{ .Parent.Params.title | replaceRE `\{\{[%\|\<]?\ *vendor\/name\ *[\%|\>]?\}\}` "Upsun" }} [{{ .Params.title | replaceRE `\{\{[%\|\<]?\ *vendor\/name\ *[\%|\>]?\}\}` "Upsun" }}]({{ $upsunUrl }}{{ .RelPermalink | replaceRE `.html` `.md` }})
{{ end }}
{{- .RenderShortcodes
| replaceRE `<a href=\"([][a-zA-Z0-9\.\_\!\+\#:='\''\;,\/\{\}\(\)\&><↗\ -]+)?\".*\>(.*)?<\/a>` `[$2]($1)`
| replaceRE ` ([a-zA-Z0-9\@:-]){2,}="([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&><↗\ -]{0,})"` ``
| replaceRE `(<!--[][a-zA-Z0-9_\ \/:@()\*\?#,.-]+-->)` ``
| replaceRE `(<style>[][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)#\&\n\ -]+<\/style>)` ``
| replaceRE `<div>Terminal<\/div>\n` ``
| replaceRE `<div>\.upsun\/config\.yaml<\/div>\n` ``
| replaceRE `<div>export\-config\.sh<\/div>\n` ``
| replaceRE `<div\nx\-data(.*\n)+>` ""
| replaceRE `<(pre|var|span|p|div|a).*?>` ``
| replaceRE `<\/(pre|var|span|p|div|a|li)>` ``
| replaceRE `<code>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/code>` "`$1`"
| replaceRE `<code>(.*)+\n` "```\n$1\n"
| replaceRE `<\/code>` "\n```"
| replaceRE `<img\ ?\/?>` ``
| replaceRE `<h3\b[^>]*>\n*\ *(.*)\n*\ *<\/h3>` "\n\n### $1\n"
| replaceRE `<h4\b[^>]*>\n*\ *(.*)\n*\ *<\/h4>` "\n\n#### $1"
| replaceRE `<\/br>` " "
| replaceRE `(\[.*\])?\(\/((.*)?\.md(.*)?)\)` "$1(https://docs.upsun.com/$3.md$4)"
| replaceRE `\[(.*)?\]\((#.*)?\)` `$1`

| replaceRE `\ *<thead>(\n|\ )*<tr>(\n|\ )*<th>` "\n| <th>"
| replaceRE `((\|)?.*<th>(.*)?<\/th>(\n|\ )*)` `$2 $3 |`
| replaceRE `\ *(\n|\ )*<tr>(\n|\ )*<td>\n*\ *` "\n| <td>"
| replaceRE `((\|)?.*<td>(.*)?<\/td>(\n|\ )*)` `$2 $3 |`
| replaceRE `\n\ *<\/?(tbody|thead|table)>` ``
| replaceRE `\ *<\/?(tr)>` ``

| replaceRE `\n*<path\b[^>]*>(.*?)<\/path>\n*` ""
| replaceRE `\n*\ *<\/?(g|path)>` ""
| replaceRE `<svg>(<title>)?(.*?)(<\/title>)?\n*(.*?)<\/svg>` ""
| replaceRE `<details>\n` ""
| replaceRE `<\/details>\n` ""
| replaceRE `\ *<summary><b>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/b><\/summary>` "**$1**"

| replaceRE `<title>(.*)?<\/title>` "**$1**"
| replaceRE `<\/?(ol|ul)>` ""
| replaceRE `<li>\n?` ` - `

| replaceRE `<strong>` "**"
| replaceRE `<\/strong>` "**"
| replaceRE `(\n\ *)+\n` "\n\n"

| replaceRE `(\[.*\])?\(\/((\/images\/)?(.*)?(.*)?)\)` "$1(https://docs.upsun.com/$4)"

| replaceRE `(https:\/\/docs.upsun.com.*)?.html` `$1.md`

| htmlUnescape
-}}
{{ partial "llms/replace-html.md" ( dict "Context" . "content" .RenderShortcodes "title" .Params.title ) }}
{{- end }}

## Example of a Symfony skeleton config
Expand Down
52 changes: 1 addition & 51 deletions themes/psh-docs/layouts/_default/home.markdown.md
Original file line number Diff line number Diff line change
@@ -1,51 +1 @@
{{- $upsunUrl := "https://docs.upsun.com" -}}

{{- if .Params.title }}# {{ .Params.title | replaceRE `\{\{[%\|\<]?\ *vendor\/name\ *[\%|\>]?\}\}` "Upsun" }}
{{ end }}
{{- .RenderShortcodes
| replaceRE `<a href=\"([][a-zA-Z0-9\.\_\!\+\#:='\''\;,\/\{\}\(\)\&><↗\ -]+)?\".*\>(.*)?<\/a>` `[$2]($1)`
| replaceRE ` ([a-zA-Z0-9\@:-]){2,}="([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&><↗\ -]{0,})"` ``
| replaceRE `(<!--[][a-zA-Z0-9_\ \/:@()\*\?#,.-]+-->)` ``
| replaceRE `(<style>[][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)#\&\n\ -]+<\/style>)` ``
| replaceRE `<div>Terminal<\/div>\n` ``
| replaceRE `<div>\.upsun\/config\.yaml<\/div>\n` ``
| replaceRE `<div>export\-config\.sh<\/div>\n` ``
| replaceRE `<div\nx\-data(.*\n)+>` ""
| replaceRE `<(pre|var|span|p|div|a).*?>` ``
| replaceRE `<\/(pre|var|span|p|div|a|li)>` ``
| replaceRE `<code>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/code>` "`$1`"
| replaceRE `<code>(.*)+\n` "```\n$1\n"
| replaceRE `<\/code>` "\n```"
| replaceRE `<img\ ?\/?>` ``
| replaceRE `<h3\b[^>]*>\n*\ *(.*)\n*\ *<\/h3>` "\n\n### $1\n"
| replaceRE `<h4\b[^>]*>\n*\ *(.*)\n*\ *<\/h4>` "\n\n#### $1"
| replaceRE `<\/br>` " "
| replaceRE `(\[.*\])?\(\/((.*)?\.md(.*)?)\)` "$1(https://docs.upsun.com/$3.md$4)"
| replaceRE `\[(.*)?\]\((#.*)?\)` `$1`

| replaceRE `\ *(<thead>)?(\n|\ )*<tr>(\n|\ )*<th>` "\n| <th>"
| replaceRE `((\|)?.*<th>(.*)?<\/th>(\n|\ )*)` `$2 $3 |`
| replaceRE `\ *(\n|\ )*<tr>(\n|\ )*<td>\n*\ *` "\n| <td>"
| replaceRE `((\|)?.*<td>(.*)?<\/td>(\n|\ )*)` `$2 $3 |`
| replaceRE `\n\ *<\/?(tbody|thead|table)>` ``
| replaceRE `\ *<\/?(tr)>` ``

| replaceRE `\n*<path\b[^>]*>(.*?)<\/path>\n*` ""
| replaceRE `\n*\ *<\/?(g|path)>` ""
| replaceRE `<svg>(<title>)?(.*?)(<\/title>)?\n*(.*?)<\/svg>` ""
| replaceRE `<details>\n` ""
| replaceRE `<\/details>\n` ""
| replaceRE `\ *<summary>(<b>|\*\*)?([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)(<\/b>|\*\*)?` "**$1**"

| replaceRE `<title>(.*)?<\/title>` "**$1**"
| replaceRE `<\/?(ol|ul)>` ""
| replaceRE `<li>\n?` ` - `

| replaceRE `<strong>` "**"
| replaceRE `<\/strong>` "**"
| replaceRE `(\n\ *)+\n` "\n\n"

| replaceRE `(\[.*\])?\(\/((\/images\/)?(.*)?(.*)?)\)` "$1(https://docs.upsun.com/$4)"

| htmlUnescape
-}}
{{ partial "llms/replace-html.md" ( dict "Context" . "content" .RenderShortcodes "title" .Params.title ) }}
58 changes: 1 addition & 57 deletions themes/psh-docs/layouts/_default/section.markdown.md
Original file line number Diff line number Diff line change
@@ -1,57 +1 @@
{{- $upsunUrl := "https://docs.upsun.com" -}}

{{- if .Params.title }}# {{ .Params.title | replaceRE `\{\{[%\|\<]?\ *vendor\/name\ *[\%|\>]?\}\}` "Upsun" }}
{{ end }}
{{- .RenderShortcodes
| replaceRE `<a href=\"([][a-zA-Z0-9\.\_\!\+\#:='\''\;,\/\{\}\(\)\&><↗\ -]+)?\".*\>(.*)?<\/a>` `[$2]($1)`
| replaceRE ` ([a-zA-Z0-9\@:-]){2,}="([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&><↗\ -]{0,})"` ``
| replaceRE `(<!--[][a-zA-Z0-9_\ \/:@()\*\?#,.-]+-->)` ``
| replaceRE `(<style>[][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)#\&\n\ -]+<\/style>)` ``
| replaceRE `<div>Terminal<\/div>\n` ``
| replaceRE `<div>\.upsun\/config\.yaml<\/div>\n` ``
| replaceRE `<div>export\-config\.sh<\/div>\n` ``
| replaceRE `<div\nx\-data(.*\n)+>` ""
| replaceRE `<(pre|var|span|p|div|a).*?>` ``
| replaceRE `<\/(pre|var|span|p|div|a|li)>` ``
| replaceRE `<code>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/code>` "`$1`"
| replaceRE `<code>(.*)+\n` "```\n$1\n"
| replaceRE `<\/code>` "\n```"
| replaceRE `<img\ ?\/?>` ``
| replaceRE `<h3\b[^>]*>\n*\ *(.*)\n*\ *<\/h3>` "\n\n### $1\n"
| replaceRE `<h4\b[^>]*>\n*\ *(.*)\n*\ *<\/h4>` "\n\n#### $1"
| replaceRE `<\/br>` " "
| replaceRE `(\[.*\])?\(\/((.*)?\.md(.*)?)\)` "$1(https://docs.upsun.com/$3.md$4)"
| replaceRE `\[(.*)?\]\((#.*)?\)` `$1`

| replaceRE `\ *(<thead>)?(\n|\ )*<tr>(\n|\ )*<th>` "\n| <th>"
| replaceRE `((\|)?.*<th>(.*)?<\/th>(\n|\ )*)` `$2 $3 |`
| replaceRE `\ *(\n|\ )*<tr>(\n|\ )*<td>\n*\ *` "\n| <td>"
| replaceRE `((\|)?.*<td>(.*)?<\/td>(\n|\ )*)` `$2 $3 |`
| replaceRE `\n\ *<\/?(tbody|thead|table)>` ``
| replaceRE `\ *<\/?(tr)>` ``

| replaceRE `\n*<path\b[^>]*>(.*?)<\/path>\n*` ""
| replaceRE `\n*\ *<\/?(g|path)>` ""
| replaceRE `<svg>(<title>)?(.*?)(<\/title>)?\n*(.*?)<\/svg>` ""
| replaceRE `<details>\n` ""
| replaceRE `<\/details>\n` ""
| replaceRE `\ *<summary>(<b>|\*\*)?([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)(<\/b>|\*\*)?` "**$1**"
| replaceRE `<\/summary>` ""


| replaceRE `<title>(.*)?<\/title>` "**$1**"
| replaceRE `<\/?(ol|ul)>` ""
| replaceRE `<li>\n?` ` - `

| replaceRE `<strong>` "**"
| replaceRE `<\/strong>` "**"
| replaceRE `(\n\ *)+\n` "\n\n"

| replaceRE `(\[.*\])?\(\/((\/images\/)?(.*)?(.*)?)\)` "$1(https://docs.upsun.com/$4)"

| htmlUnescape
-}}

{{- range .Pages -}}
{{- partial "llms/list" ( dict "Context" . "sections" .CurrentSection ) -}}
{{- end -}}
{{ partial "llms/replace-html.md" ( dict "Context" . "content" .RenderShortcodes "title" .Params.title ) }}
51 changes: 1 addition & 50 deletions themes/psh-docs/layouts/_default/single.markdown.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,2 @@
{{- $upsunUrl := "https://docs.upsun.com" -}}
{{ partial "llms/replace-html.md" ( dict "Context" . "content" .RenderShortcodes "title" .Params.title ) }}

{{- if .Params.title }}# {{ .Params.title | replaceRE `\{\{[%\|\<]?\ *vendor\/name\ *[\%|\>]?\}\}` "Upsun" }}
{{ end }}
{{- .RenderShortcodes
| replaceRE `<a href=\"([][a-zA-Z0-9\.\_\!\+\#:='\''\;,\/\{\}\(\)\&><↗\ -]+)?\".*\>(.*)?<\/a>` `[$2]($1)`
| replaceRE ` ([a-zA-Z0-9\@:-]){2,}="([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&><↗\ -]{0,})"` ``
| replaceRE `(<!--[][a-zA-Z0-9_\ \/:@()\*\?#,.-]+-->)` ``
| replaceRE `(<style>[][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)#\&\n\ -]+<\/style>)` ``
| replaceRE `<div>Terminal<\/div>\n` ``
| replaceRE `<div>\.upsun\/config\.yaml<\/div>\n` ``
| replaceRE `<div>export\-config\.sh<\/div>\n` ``
| replaceRE `<div\nx\-data(.*\n)+>` ""
| replaceRE `<(pre|var|span|p|div|a).*?>` ``
| replaceRE `<\/(pre|var|span|p|div|a|li)>` ``
| replaceRE `<code>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/code>` "`$1`"
| replaceRE `<code>(.*)+\n` "```\n$1\n"
| replaceRE `<\/code>` "\n```"
| replaceRE `<img\ ?\/?>` ``
| replaceRE `<h3\b[^>]*>\n*\ *(.*)\n*\ *<\/h3>` "\n\n### $1\n"
| replaceRE `<h4\b[^>]*>\n*\ *(.*)\n*\ *<\/h4>` "\n\n#### $1"
| replaceRE `<\/br>` " "
| replaceRE `(\[.*\])?\(\/((.*)?\.md(.*)?)\)` "$1(https://docs.upsun.com/$3.md$4)"
| replaceRE `\[(.*)?\]\((#.*)?\)` `$1`

| replaceRE `\ *(<thead>)?(\n|\ )*<tr>(\n|\ )*<th>` "\n| <th>"
| replaceRE `((\|)?.*<th>(.*)?<\/th>(\n|\ )*)` `$2 $3 |`
| replaceRE `\ *(\n|\ )*<tr>(\n|\ )*<td>\n*\ *` "\n| <td>"
| replaceRE `((\|)?.*<td>(.*)?<\/td>(\n|\ )*)` `$2 $3 |`
| replaceRE `\n\ *<\/?(tbody|thead|table)>` ``
| replaceRE `\ *<\/?(tr)>` ``

| replaceRE `\n*<path\b[^>]*>(.*?)<\/path>\n*` ""
| replaceRE `\n*\ *<\/?(g|path)>` ""
| replaceRE `<svg>(<title>)?(.*?)(<\/title>)?\n*(.*?)<\/svg>` ""
| replaceRE `<details>\n` ""
| replaceRE `<\/details>\n` ""
| replaceRE `\ *<summary><b>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/b><\/summary>` "**$1**"

| replaceRE `<title>(.*)?<\/title>` "**$1**"
| replaceRE `<\/?(ol|ul)>` ""
| replaceRE `<li>\n?` ` - `

| replaceRE `<strong>` "**"
| replaceRE `<\/strong>` "**"
| replaceRE `(\n\ *)+\n` "\n\n"

| replaceRE `(\[.*\])?\(\/((\/images\/)?(.*)?(.*)?)\)` "$1(https://docs.upsun.com/$4)"

| htmlUnescape
}}
50 changes: 50 additions & 0 deletions themes/psh-docs/layouts/partials/llms/replace-html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- if .title }}# {{ .title | replaceRE `\{\{[%\|\<]?\ *vendor\/name\ *[\%|\>]?\}\}` "Upsun" }}
{{ end }}
{{- .content
| replaceRE `<a href=\"([][a-zA-Z0-9\.\_\!\+\#:='\''\;,\/\{\}\(\)\&><↗\ -]+)?\".*\>(.*)?<\/a>` `[$2]($1)`
| replaceRE ` ([a-zA-Z0-9\@:-]){2,}="([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&><↗\ -]{0,})"` ``
| replaceRE `(<!--[][a-zA-Z0-9_\ \/:@()\*\?#,.-]+-->)` ``
| replaceRE `(<style>[][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)#\&\n\ -]+<\/style>)` ``
| replaceRE `<div>Terminal<\/div>\n` ``
| replaceRE `<div>\.upsun\/config\.yaml<\/div>\n` ``
| replaceRE `<div>export\-config\.sh<\/div>\n` ``
| replaceRE `<div\nx\-data(.*\n)+>` ""
| replaceRE `<(pre|var|span|p|div|a).*?>` ``
| replaceRE `<\/(pre|var|span|p|div|a|li)>` ``
| replaceRE `<code>([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)<\/code>` "`$1`"
| replaceRE `<code>(.*)+\n` "```\n$1\n"
| replaceRE `<\/code>` "\n```"
| replaceRE `<img\ ?\/?>` ``
| replaceRE `<h3\b[^>]*>\n*\ *(.*)\n*\ *<\/h3>` "\n\n### $1\n"
| replaceRE `<h4\b[^>]*>\n*\ *(.*)\n*\ *<\/h4>` "\n\n#### $1"
| replaceRE `<\/br>` " "
| replaceRE `(\[.*\])?\(\/((.*)?\.md(.*)?)\)` "$1(https://docs.upsun.com/$3.md$4)"
| replaceRE `\[(.*)?\]\((#.*)?\)` `$1`

| replaceRE `\ *(<thead>)?(\n|\ )*<tr>(\n|\ )*<th>` "\n| <th>"
| replaceRE `((\|)?.*<th>(.*)?<\/th>(\n|\ )*)` `$2 $3 |`
| replaceRE `\ *(\n|\ )*<tr>(\n|\ )*<td>\n*\ *` "\n| <td>"
| replaceRE `((\|)?.*<td>(.*)?<\/td>(\n|\ )*)` `$2 $3 |`
| replaceRE `\n\ *<\/?(tbody|thead|table)>` ``
| replaceRE `\ *<\/?(tr)>` ``

| replaceRE `\n*<path\b[^>]*>(.*?)<\/path>\n*` ""
| replaceRE `\n*\ *<\/?(g|path)>` ""
| replaceRE `<svg>(<title>)?(.*?)(<\/title>)?\n*(.*?)<\/svg>` ""
| replaceRE `<details>\n` ""
| replaceRE `<\/details>\n` ""
| replaceRE `\ *<summary>(<b>|\*\*)?([][a-zA-Z0-9\.\_\!\+:='\''\;,\/\{\}\(\)\&↗\ -]+)(<\/b>|\*\*)?` "**$1**"
| replaceRE `<\/summary>` ""

| replaceRE `<title>(.*)?<\/title>` "**$1**"
| replaceRE `<\/?(ol|ul)>` ""
| replaceRE `<li>\n?` ` - `

| replaceRE `<strong>` "**"
| replaceRE `<\/strong>` "**"
| replaceRE `(\n\ *)+\n` "\n\n"

| replaceRE `(\[.*\])?\(\/((\/images\/)?(.*)?(.*)?)\)` "$1(https://docs.upsun.com/$4)"

| htmlUnescape
}}

0 comments on commit fc556ae

Please sign in to comment.