From a0684e5add17d66d951b691c747981f1c32f91da Mon Sep 17 00:00:00 2001 From: younsl Date: Mon, 18 Nov 2024 01:26:06 +0900 Subject: [PATCH] feat(footer): Add fallback footer and improve file reading - Use resources.Get for safer file reading instead of readFile - Prevents directory traversal attacks - Ensures file access within Hugo's assets pipeline - Better error handling for missing files - Add fallback copyright notice when footer.md is not found - Add warning message for fallback to default footer --- layouts/partials/footer.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 37fe512..3b9522e 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,4 +1,10 @@ {{ if site.Params.theme_config.isShowFooter }} - {{ $footerContent := readFile "layouts/footer.md" }} - {{ $footerContent | markdownify }} -{{ end }} \ No newline at end of file + {{ with resources.Get "layouts/footer.md" }} + {{ .Content | markdownify }} + {{ else }} + {{ warnf "layouts/footer.md file is not found, fallback to the default copyright" }} + + {{ end }} +{{ end }}