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