Skip to content

Commit

Permalink
fix absolute paths in api doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecornec authored and mergify-bot committed Apr 15, 2021
1 parent 8a8e107 commit 38910b8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
33 changes: 31 additions & 2 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_haskell//docs/pandoc:pandoc.bzl", "set_site_end_location")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

bool_flag(
name = "render_dev_website",
build_setting_default = False,
)

config_setting(
name = "dev_website_config",
flag_values = {
"render_dev_website": "True",
},
)

set_site_end_location(
name = "set_site_end_location",
site_end_location = select({
":dev_website_config": "/api",
"//conditions:default": "",
}),
)

libraries = [
"defs",
Expand Down Expand Up @@ -49,6 +71,7 @@ libraries = [
outs = ["haskell/%s.html" % lib],
cmd = """\
$(execpath //docs/pandoc) \
-V path_prefix=$(SITE_END_LOCATION)\
-f markdown \
-t html \
-s \
Expand All @@ -57,8 +80,9 @@ $(execpath //docs/pandoc) \
--toc \
--toc-depth=2 \
-o $(OUTS) \
$(execpath :%s_md)
""" % lib,
$(execpath :{}_md)
""".format(lib),
toolchains = [":set_site_end_location"],
tools = ["//docs/pandoc"],
),
)
Expand Down Expand Up @@ -90,6 +114,7 @@ genrule(
outs = ["nav.html"],
cmd = """\
$(execpath //docs/pandoc) \
-V path_prefix=$(SITE_END_LOCATION)\
-f markdown \
-t html \
-s \
Expand All @@ -99,6 +124,7 @@ $(execpath //docs/pandoc) \
--metadata-file=$(execpath :metadata) \
<<<""
""",
toolchains = [":set_site_end_location"],
tools = ["//docs/pandoc"],
)

Expand All @@ -115,6 +141,7 @@ genrule(
cmd = """\
# Render overview page body.
$(execpath //docs/pandoc) \
-V path_prefix=$(SITE_END_LOCATION)\
-f markdown \
-t html \
-s \
Expand All @@ -125,6 +152,7 @@ $(execpath //docs/pandoc) \
<<<""
# Render full overview page including navigation sidebar.
$(execpath //docs/pandoc) \
-V path_prefix=$(SITE_END_LOCATION)\
-f html \
-t html \
-s \
Expand All @@ -137,6 +165,7 @@ $(execpath //docs/pandoc) \
--metadata-file=$(execpath :metadata) \
index_body.html
""",
toolchains = [":set_site_end_location"],
tools = ["//docs/pandoc"],
)

Expand Down
12 changes: 12 additions & 0 deletions docs/pandoc/pandoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ pandoc_toolchain(
""",
**kwargs
)

def _set_site_end_location(ctx):
return [
platform_common.TemplateVariableInfo({
"SITE_END_LOCATION": ctx.attr.site_end_location,
}),
]

set_site_end_location = rule(
implementation = _set_site_end_location,
attrs = {"site_end_location": attr.string()},
)
4 changes: 2 additions & 2 deletions docs/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$-- Translation of Skydoc Jinja templates to pandoc
$-- https://github.com/bazelbuild/skydoc/blob/b8a32e0/skydoc/templates
$for(module)$
<h2><a href="/haskell/$module.name$.html" id="$module.name$">$module.summary$</a></h2>
<h2><a href="$path_prefix$/haskell/$module.name$.html" id="$module.name$">$module.summary$</a></h2>
<table class="overview-table">
<colgroup>
<col class="col-name" />
Expand All @@ -25,7 +25,7 @@ <h2><a href="/haskell/$module.name$.html" id="$module.name$">$module.summary$</a
$for(module.symbol)$
<tr>
<td>
<a href="/haskell/$module.name$.html#$module.symbol.name$">
<a href="$path_prefix$/haskell/$module.name$.html#$module.symbol.name$">
<code>$module.symbol.name$</code>
</a>
</td>
Expand Down
6 changes: 3 additions & 3 deletions docs/templates/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
<span class="mdl-layout-title">Bazel</span>
<nav class="drawer-nav">
<ul class="drawer-nav">
<li><a href="/index.html">Overview</a></li>
<li><a href="$path_prefix$/index.html">Overview</a></li>
$for(module)$
<li>
<a href="/haskell/$module.name$.html">$module.summary$</a>
<a href="$path_prefix$/haskell/$module.name$.html">$module.summary$</a>
<ul>
$for(module.symbol)$
<li>
<a href="/haskell/$module.name$.html#$module.symbol.name$" $if(module.symbol.summary)$title="$module.symbol.summary$"$endif$>
<a href="$path_prefix$/haskell/$module.name$.html#$module.symbol.name$" $if(module.symbol.summary)$title="$module.symbol.summary$"$endif$>
$module.symbol.name$
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion serve-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ finish() {

trap finish EXIT

bazel build //docs:api_html
bazel build //docs:api_html --//docs:render_dev_website
mkdir "$SCRATCH/api"
unzip -d "$SCRATCH/api" bazel-bin/docs/api_html-stardoc.zip

Expand Down

0 comments on commit 38910b8

Please sign in to comment.