mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
fdfd772100
* feat(File Tree): add `file-tree` shortcode support * feat(file-tree): add ignoreList parameter to file-tree shortcode * feat(file-tree): enhance file-tree shortcode with ignoreList and folderSlash options * feat(file-tree): enhance file-tree shortcode to support data mode * feat(file-tree): enhance file-tree shortcode to support file mode * feat(file-tree): improve content parsing in file-tree shortcode * feat(file-tree): improve root path validation and error handling in filesystem mode * test(file-tree): add unit tests for `file-tree` shortcode * feat(file-tree): add file-tree code block rendering support * refactor(file-tree): extract filesystem scanning to get-file-tree partial Move directory traversal and root path validation to a separate partial function, consolidating all filesystem-related logic in one place. This simplifies the shortcode implementation and ensures a unified data format for rendering. * docs(readme): extend code fence and shortcode support for file tree in documentation * feat(file-tree): add fullRootName parameter for root path display in file tree * feat(file-tree): add language parameter to get-file-tree function * feat(file-tree): add highlightList parameter for file-tree shortcode * perf(file-tree): add level param for get-file-tree function to descend only level directories deep
52 lines
1.9 KiB
HTML
52 lines
1.9 KiB
HTML
{{- /*
|
|
Render hook for file-tree code blocks
|
|
Alternative to file-tree shortcode's inner content rendering.
|
|
|
|
Supported attributes:
|
|
- level: The expand level of the tree (expand all: -1, collapse all: 0, default: 1)
|
|
- folderSlash: Whether to append a trailing "/" to folder names (default: false)
|
|
- ignoreList: List of file or folder names to ignore, separated by commas
|
|
- highlightList: List of file or folder names to highlight, separated by commas
|
|
|
|
Content format: YAML/JSON/TOML with the following item structure:
|
|
name: string - The name of the file or folder
|
|
type: string - Type of item, either "dir" (directory) or "file"
|
|
children?: array - (Optional) Array of child items, only valid for directories
|
|
|
|
Example usage:
|
|
```file-tree {level=2 folderSlash=true}
|
|
- name: my-project
|
|
type: dir
|
|
children:
|
|
- name: src
|
|
type: dir
|
|
- name: package.json
|
|
type: file
|
|
```
|
|
*/ -}}
|
|
|
|
{{- $pageConfig := dict | merge .Page.Params.filetree | merge .Page.Site.Params.filetree -}}
|
|
{{- $config := .Attributes | merge $pageConfig -}}
|
|
{{- $level := cond (isset $config "level") ($config.level | int) 1 -}}
|
|
{{- $folderSlash := $config.folderslash | default false -}}
|
|
{{- $ignoreList := union (apply (split (.Attributes.ignorelist | default "") ",") "trim" "." " ") $pageConfig.ignorelist -}}
|
|
{{- $highlightList := apply (split (.Attributes.highlightlist | default "") ",") "trim" "." " " -}}
|
|
|
|
{{- $content := strings.TrimSpace .Inner | default "" -}}
|
|
{{- $treeData := slice -}}
|
|
{{- with $content -}}
|
|
{{- $treeData = . | unmarshal -}}
|
|
{{- if reflect.IsMap $treeData -}}
|
|
{{- $treeData = $treeData.filetree -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $options := dict
|
|
"items" $treeData
|
|
"level" $level
|
|
"folderSlash" $folderSlash
|
|
"ignoreList" $ignoreList
|
|
"highlightList" $highlightList
|
|
-}}
|
|
{{- partial "plugin/file-tree.html" $options -}}
|