diff --git a/apps/test/content/posts/file-tree-test/index.md b/apps/test/content/posts/file-tree-test/index.md index 4f2ce77d..8498152e 100644 --- a/apps/test/content/posts/file-tree-test/index.md +++ b/apps/test/content/posts/file-tree-test/index.md @@ -151,6 +151,12 @@ Trying the file not found case (should fallback to next mode): {{< file-tree "content" />}} +{{< file-tree name="{path}" />}} + +{{< file-tree name="FixIt/apps/test" />}} + +{{< file-tree path="posts" name="{path}" />}} + ### Named parameters {{< file-tree path="data" level=2 />}} diff --git a/assets/css/_shortcodes/_file-tree.scss b/assets/css/_shortcodes/_file-tree.scss index 182d642d..afad55f1 100644 --- a/assets/css/_shortcodes/_file-tree.scss +++ b/assets/css/_shortcodes/_file-tree.scss @@ -103,7 +103,7 @@ } > .file-tree-label .file-tree-icon::before { - content: '\f07b'; + --fa: '\f07b'; } } } diff --git a/layouts/_partials/function/get-file-tree.html b/layouts/_partials/function/get-file-tree.html index 1e0eaa9d..192c4102 100644 --- a/layouts/_partials/function/get-file-tree.html +++ b/layouts/_partials/function/get-file-tree.html @@ -13,9 +13,9 @@ @param {int} [deep=0] - Current depth level for recursive calls @param {array} [ignoreList] - List of file or folder names to ignore @param {boolean} [isRecursive=false] - Internal flag for recursive calls - @param {boolean} [fullRootName=false] - Whether to use the full root path as the root name + @param {string} [name] - Project name for the root node, if set to `{path}`, uses the full root path @param {string} [lang] - Page language for multilingual sites - @param {boolean} [log=true] - Whether to log warnings + @param {boolean} [log=false] - Whether to log warnings @return {array} Array of tree items with structure: {name, type, children?}, or empty array if root doesn't exist */ -}} @@ -25,7 +25,6 @@ {{- $isRecursive := .isRecursive | default false -}} {{- $_ignoreList := slice ".DS_Store" "Thumbs.db" ".directory" ".git" "node_modules" "public" -}} {{- $ignoreList := .ignoreList | default slice | union $_ignoreList -}} -{{- $fullRootName := .fullRootName | default false -}} {{- $_debug := (site.Store.Get "devOpts").debug -}} {{- if $isRecursive -}} @@ -78,9 +77,9 @@ {{- if $rootIsExists -}} {{- $f := os.Stat $root -}} {{- /* Determine the root name for display */ -}} - {{- $rootLabel := $f.Name -}} + {{- $rootLabel := .name | default $f.Name -}} {{- $rootClean := path.Clean $root -}} - {{- if $fullRootName | and (ne $rootClean "/") | and (ne $rootClean ".") -}} + {{- if eq .name "{path}" -}} {{- $rootLabel = $rootClean -}} {{- end -}} @@ -93,7 +92,7 @@ {{- $result = slice (dict "name" $rootLabel "type" "dir" "children" $children) -}} {{- else -}} {{- /* Root doesn't exist, emit warning if context provided */ -}} - {{- if .log | default true -}} + {{- if .log | default false -}} {{- warnidf "warning-file-tree" "[get-file-tree]: The root path does not exist: %s." $root -}} {{- end -}} {{- end -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index e1b93094..a9ad7a81 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.2-20260109141516-b29368c3" -}} +{{- hugo.Store.Set "version" "v0.4.2-20260114101213-fdfd7721" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/_shortcodes/file-tree.html b/layouts/_shortcodes/file-tree.html index 4719f58a..9b351fbd 100644 --- a/layouts/_shortcodes/file-tree.html +++ b/layouts/_shortcodes/file-tree.html @@ -9,7 +9,7 @@ @param {string} [data] - The name of the data file in data/filetree/ directory. (JSON/YAML/TOML) @param {string} [ignoreList=""] - List of file or folder names to ignore, separated by commas @param {string} [highlightList=""] - List of file or folder names to highlight, separated by commas - @param {boolean} [fullRootName=false] - Whether to use the full root path as the root name when scanning filesystem + @param {string} [name] - Project name for the root node, if set to `{path}`, uses the full root path Priority order (highest to lowest): 1. Inline content (shortcode body) - Parse tree data from shortcode body @@ -63,7 +63,6 @@ {{- $supportExts := slice ".yml" ".yaml" ".json" ".toml" -}} {{- $ignoreList := union (apply (split (.Get "ignoreList" | default "") ",") "trim" "." " ") $config.ignorelist -}} {{- $highlightList := apply (split (.Get "highlightList" | default "") ",") "trim" "." " " -}} -{{- $fullRootName := .Get "fullRootName" | default false -}} {{- /* Shortcode body */ -}} {{- $content := strings.TrimSpace .Inner | default "" -}} @@ -100,10 +99,9 @@ {{- end -}} {{- end -}} -{{- /* Filesystem mode: scan directory structure */ -}} +{{- /* Filesystem mode: build structured tree data from filesystem */ -}} {{- if not $treeData -}} - {{- /* Build structured tree data from filesystem */ -}} - {{- $buildOptions := dict "root" $root "ignoreList" $ignoreList "deep" 0 "fullRootName" $fullRootName "lang" .Page.Language "log" false -}} + {{- $buildOptions := dict "root" $root "ignoreList" $ignoreList "name" (.Get "name") "lang" .Page.Language -}} {{- with partial "function/get-file-tree.html" $buildOptions -}} {{- $treeData = . -}} {{- else -}}