Compare commits

..

3 Commits

Author SHA1 Message Date
Xin
14036ffea6 feat: enhance FlexSearch encoding for CJK support (#553)
- Added support for CJK (Chinese, Japanese, Korean) languages in FlexSearch encoding.
- Introduced `isCJK` function to detect language and select appropriate encoding method.
- Implemented `encodeCJK` and `encodeDefault` functions for different tokenization strategies.
2025-01-18 18:54:54 +00:00
a1232ecf9f fix: skip image process on svgs and remote images (#551) 2025-01-18 17:05:13 +00:00
a933f464f5 docs: fix wrong param footer (#543)
it has changed 709a407b2e/layouts/partials/footer.html (L40C40-L40C56)
2025-01-07 10:51:00 +00:00
3 changed files with 28 additions and 11 deletions

View File

@ -195,8 +195,19 @@ document.addEventListener("DOMContentLoaded", function () {
*/ */
async function preloadIndex() { async function preloadIndex() {
const tokenize = '{{- site.Params.search.flexsearch.tokenize | default "forward" -}}'; const tokenize = '{{- site.Params.search.flexsearch.tokenize | default "forward" -}}';
const isCJK = () => {
const lang = document.documentElement.lang || "en";
return lang.startsWith("zh") || lang.startsWith("ja") || lang.startsWith("ko");
}
const encodeCJK = (str) => str.replace(/[\x00-\x7F]/g, "").split("");
const encodeDefault = (str) => (""+str).toLocaleLowerCase().split(/[\p{Z}\p{S}\p{P}\p{C}]+/u);
const encodeFunction = isCJK() ? encodeCJK : encodeDefault;
window.pageIndex = new FlexSearch.Document({ window.pageIndex = new FlexSearch.Document({
tokenize, tokenize,
encode: encodeFunction,
cache: 100, cache: 100,
document: { document: {
id: 'id', id: 'id',
@ -207,6 +218,7 @@ document.addEventListener("DOMContentLoaded", function () {
window.sectionIndex = new FlexSearch.Document({ window.sectionIndex = new FlexSearch.Document({
tokenize, tokenize,
encode: encodeFunction,
cache: 100, cache: 100,
document: { document: {
id: 'id', id: 'id',

View File

@ -195,7 +195,7 @@ You can add extra section in the footer by creating a file `layouts/partials/cus
The added section will be added before the copyright section in the footer. The added section will be added before the copyright section in the footer.
You can use [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) and [Hugo template syntax](https://gohugo.io/templates/) to add your own content. You can use [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) and [Hugo template syntax](https://gohugo.io/templates/) to add your own content.
Hugo variables available in the footer section are: `.switchesVisible` and `.copyrightVisible`. Hugo variables available in the footer section are: `.switchesVisible` and `.displayCopyright`.
## Custom Layouts ## Custom Layouts

View File

@ -15,16 +15,21 @@
{{- $options := .Get "options" | default "800x webp q80" -}} {{- $options := .Get "options" | default "800x webp q80" -}}
{{- $process := .Get "process" | default (printf "%s %s" $method $options) -}} {{- $process := .Get "process" | default (printf "%s %s" $method $options) -}}
{{- with or (.Page.Resources.Get $image) (resources.Get $image) -}} {{- if and $image (not (urls.Parse $image).Scheme) -}}
{{/* Retrieve the $image resource from local or global resources */}} {{- with or (.Page.Resources.Get $image) (resources.Get $image) -}}
{{- $processed := .Process $process -}} {{/* .Process does not work on svgs */}}
{{- $width = $processed.Width -}} {{- if (not (eq .MediaType.SubType "svg")) -}}
{{- $height = $processed.Height -}} {{/* Retrieve the $image resource from local or global resources */}}
{{- $image = $processed.RelPermalink -}} {{- $processed := .Process $process -}}
{{ else }} {{- $width = $processed.Width -}}
{{/* Otherwise, use relative link of the image */}} {{- $height = $processed.Height -}}
{{- if hasPrefix $image "/" -}} {{- $image = $processed.RelPermalink -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}} {{- end -}}
{{ else }}
{{/* Otherwise, use relative link of the image */}}
{{- if hasPrefix $image "/" -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}}
{{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}