a .md file starting with _ is a fragment, not a bundle
Found by serving the include evidence: `tools.md` beside a bundle's index was
itself scanned as a bundle, so a file meant only to be included took a URL of its
own, appeared in its section's listing, and turned the including bundle into a
one-member series. The real binary showed the phantom series nav; no test would
have, because every fixture happened to name its partials differently.
The rule mirrors the one directories already have, `_index` excepted since that
names its directory. `{{< include file="_tools.md" >}}` is now the shape to write.
This commit is contained in:
@@ -84,6 +84,8 @@ func Scan(fsys fs.FS) ([]Bundle, error) {
|
||||
return nil
|
||||
case !strings.HasSuffix(p, ".md"):
|
||||
return nil
|
||||
case isPartial(path.Base(p)):
|
||||
return nil
|
||||
}
|
||||
data, err := fs.ReadFile(fsys, p)
|
||||
if err != nil {
|
||||
@@ -258,6 +260,20 @@ func isLangTag(s string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// isPartial reports whether a filename is a fragment rather than a bundle of its own.
|
||||
//
|
||||
// An underscore prefix, the same mark a directory already uses, with `_index` excepted because that names
|
||||
// the directory it sits in. Without this a file meant only to be included would also be a bundle: it would
|
||||
// take a URL, appear in its section's listing, and turn its bundle into a one-member series
|
||||
// (content-model.md).
|
||||
func isPartial(base string) bool {
|
||||
name := strings.TrimSuffix(base, ".md")
|
||||
if i := strings.LastIndex(name, "."); i > 0 && isLangTag(name[i+1:]) {
|
||||
name = name[:i]
|
||||
}
|
||||
return strings.HasPrefix(name, "_") && name != "_index"
|
||||
}
|
||||
|
||||
// skipDir reports whether a directory is not content: hidden, or underscore-prefixed.
|
||||
func skipDir(base string) bool {
|
||||
return strings.HasPrefix(base, ".") && base != "." || strings.HasPrefix(base, "_")
|
||||
|
||||
Reference in New Issue
Block a user