os.FileExists
os.FileExists
函數會嘗試解析相對於您專案目錄根目錄的路徑。如果找不到匹配的檔案或目錄,它會嘗試相對於 contentDir
解析該路徑。路徑的開頭分隔符 (/
) 是可選的。
假設目錄結構如下:
content/
├── about.md
├── contact.md
└── news/
├── article-1.md
└── article-2.md
該函數會返回以下結果:
{{ fileExists "content" }} → true
{{ fileExists "content/news" }} → true
{{ fileExists "content/news/article-1" }} → false
{{ fileExists "content/news/article-1.md" }} → true
{{ fileExists "news" }} → true
{{ fileExists "news/article-1" }} → false
{{ fileExists "news/article-1.md" }} → true