summaryrefslogtreecommitdiffhomepage
path: root/website/defs.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'website/defs.bzl')
-rw-r--r--website/defs.bzl41
1 files changed, 26 insertions, 15 deletions
diff --git a/website/defs.bzl b/website/defs.bzl
index 64a9d43e3..ead6a3067 100644
--- a/website/defs.bzl
+++ b/website/defs.bzl
@@ -13,6 +13,7 @@ DocInfo = provider(
"subcategory",
"weight",
"editpath",
+ "authors",
],
)
@@ -29,6 +30,7 @@ def _doc_impl(ctx):
subcategory = ctx.attr.subcategory,
weight = ctx.attr.weight,
editpath = ctx.files.src[0].short_path,
+ authors = ctx.attr.authors,
),
]
@@ -69,6 +71,7 @@ doc = rule(
doc = "The document weight.",
default = "50",
),
+ "authors": attr.string_list(),
},
)
@@ -105,31 +108,38 @@ category: {category}
subcategory: {subcategory}
weight: {weight}
editpath: {editpath}
+authors: {authors}
layout: {layout}"""
for f in dep.files.to_list():
- builder_content += ["echo Processing %s... >&2" % f.short_path]
- builder_content += ["mkdir -p $T/$(dirname %s)" % f.short_path]
-
# Is this a markdown file? If not, then we ensure that it ends up
# in the same path as the permalink for relative addressing.
if not f.basename.endswith(".md"):
- builder_content += ["mkdir -p $T/%s" % doc.permalink]
- builder_content += ["cp %s $T/%s" % (f.path, doc.permalink)]
+ builder_content.append("mkdir -p $T/%s" % doc.permalink)
+ builder_content.append("cp %s $T/%s" % (f.path, doc.permalink))
continue
+ # Is this a post? If yes, then we must put this in the _posts
+ # directory. This directory is treated specially with respect to
+ # pagination and page generation.
+ dest = f.short_path
+ if doc.layout == "post":
+ dest = "_posts/" + f.basename
+ builder_content.append("echo Processing %s... >&2" % f.short_path)
+ builder_content.append("mkdir -p $T/$(dirname %s)" % dest)
+
# Construct the header dynamically. We include the title field from
# the markdown itself, as this is the g3doc format required. The
# title will be injected by the web layout however, so we don't
# want this to appear in the document.
args = dict([(k, getattr(doc, k)) for k in dir(doc)])
- builder_content += ["title=\"$(grep -E '^# ' %s | head -n 1 | cut -d'#' -f2-)\"" % f.path]
- builder_content += ["cat >$T/%s <<EOF" % f.short_path]
- builder_content += ["---"]
- builder_content += ["title: $title"]
- builder_content += [header.format(**args)]
- builder_content += ["---"]
- builder_content += ["EOF"]
+ builder_content.append("title=\"$(grep -E '^# ' %s | head -n 1 | cut -d'#' -f2- || true)\"" % f.path)
+ builder_content.append("cat >$T/%s <<EOF" % dest)
+ builder_content.append("---")
+ builder_content.append("title: $title")
+ builder_content.append(header.format(**args))
+ builder_content.append("---")
+ builder_content.append("EOF")
# To generate the final page, we need to strip out the title (which
# was pulled above to generate the annotation in the frontmatter,
@@ -137,10 +147,11 @@ layout: {layout}"""
# that the pipeline here is almost important, as the grep will
# return non-zero if the file is empty, but we ignore that within
# the pipeline.
- builder_content += ["grep -v -E '^# ' %s | sed -e 's|^\\[TOC\\]$|- TOC\\n{:toc}|' >>$T/%s" % (f.path, f.short_path)]
+ builder_content.append("grep -v -E '^# ' %s | sed -e 's|^\\[TOC\\]$|- TOC\\n{:toc}|' >>$T/%s" %
+ (f.path, dest))
- builder_content += ["declare -r filename=$(readlink -m %s)" % tarball.path]
- builder_content += ["(cd $T && tar -zcf \"${filename}\" .)\n"]
+ builder_content.append("declare -r filename=$(readlink -m %s)" % tarball.path)
+ builder_content.append("(cd $T && tar -zcf \"${filename}\" .)\n")
ctx.actions.write(builder, "\n".join(builder_content), is_executable = True)
# Generate the tarball.