Skip to content

Commit

Permalink
docs: remove rule_hugo in place of using pandoc directly
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanhay committed Oct 18, 2021
1 parent 791a72d commit e4583a6
Show file tree
Hide file tree
Showing 24 changed files with 3,549 additions and 137 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ jobs:
- name: Build and test
run: |
nix-shell --argstr ghcVersion '${{ matrix.ghc }}' --run '
bazel build //docs'
set -euo pipefail
bazel build //docs:bundle
mkdir public
tar xvf bazel-bin/docs/bundle.tar -C public
'
- if: ${{ github.repository == 'brendanhay/amazonka' }}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: bazel-bin/docs/docs
publish_dir: public
19 changes: 16 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ versioned_http_archive(
version = "0.9.0",
)

versioned_http_archive(
name = "rules_pkg",
sha256 = "dd13c5581146da6abdee49a1a2605cd1dd8fb39bea9a870e0089aa4066b260b6",
strip_prefix = "rules_pkg-{version}/pkg",
url = "https://github.com/bazelbuild/rules_pkg/archive/{version}.tar.gz",
version = "8d542763a3959db79175404758f46c7f3f385fa5",
)

versioned_http_archive(
name = "rules_sh",
sha256 = "83a065ba6469135a35786eb741e17d50f360ca92ab2897857475ab17c0d29931",
Expand All @@ -31,12 +39,12 @@ versioned_http_archive(

versioned_http_archive(
name = "rules_haskell",
patch_args = ["-p1"],
patches = ["//:third_party/rules_haskell/haddock_index.patch"],
sha256 = "73941c142bf37df115817083c0834fbc3269c963c7049bfbc345a9c76162e918",
strip_prefix = "rules_haskell-{version}",
url = "https://github.com/tweag/rules_haskell/archive/{version}.tar.gz",
version = "ea0e70ace2432a490d4ab4c4e54617612466e584",
patches = ["//:third_party/rules_haskell/haddock_index.patch"],
patch_args = ["-p1"],
)

versioned_http_archive(
Expand Down Expand Up @@ -289,6 +297,12 @@ gazelle_cabal_dependencies()

stack_snapshot(
name = "stackage",
components = {
"pandoc": [
"lib",
"exe",
],
},
extra_deps = {
"zlib": ["@zlib.dev//:zlib"],
"digest": ["@zlib.dev//:zlib"],
Expand Down Expand Up @@ -322,7 +336,6 @@ stack_snapshot(
"filepath", # keep
"free", # keep
"generic-lens",
"ghc-prim",
"groom",
"hashable", # keep
"haskell-src-exts", # keep
Expand Down
116 changes: 72 additions & 44 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
load("@rules_haskell//haskell:defs.bzl", "haskell_doc")
load(
"@build_stack_rules_hugo//hugo:rules.bzl",
"hugo_serve",
"hugo_site",
"hugo_theme",
)

hugo_theme(
name = "theme",
srcs = [
"@hugo_theme_kube//:files",
],
)

hugo_site(
name = "docs",
config = "config.toml",
content = glob(["content/**/*"]),
data = [":packages"],
hugo = "@nixpkgs_hugo//:bin/hugo",
layouts = glob(["layouts/**/*"]),
static = [":static"] + glob(["static/**/*"]),
theme = ":theme",
)

hugo_serve(
name = "serve",
dep = [":docs"],
hugo = "@nixpkgs_hugo//:bin/hugo",
)
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

haskell_doc(
# Target name is important, otherwise `hugo_site` won't copy over the files
# if they don't have the expected directory prefix. This could be made more
# robust by using `rules_pkg/mappings.bzl:pkg_files` to assemble the directory.
name = "static",
visibility = ["//visibility:public"],
name = "docs",
# Disables generating the huge multi-package ./index.
# See: //:third_party/rules_haskell/haddock_index.patch
index = False,
# deps is auto-populated by the buildozer command in scripts/generate.
# The deps attribute is auto-populated by buildozer via scripts/generate.
deps = [
"//amazonka",
"//amazonka-alexa-business",
Expand Down Expand Up @@ -187,24 +157,82 @@ haskell_doc(
],
)

# Generate a hugo data mapping from the list of hadock directories.
genrule(
name = "packages",
srcs = [":static"],
outs = ["data/packages.yaml"],
name = "metadata",
srcs = [":docs"],
outs = ["metadata.yaml"],
cmd = """
printf 'haddock:\n' >> $@
printf 'packages:\n' >>$(OUTS)
for dir in $(locations :static); do
for dir in $(SRCS); do
dir="$${dir##*/}"
pkg="$${dir%ZS*}"
if [[ $$pkg != amazonka* ]]; then
continue
fi
printf ' %s: %s\n' "$$pkg" "$$dir" >> $@
printf ' - name: "%s"\n' "$$pkg" >>$(OUTS)
printf ' link: "/docs/%s"\n' "$$dir" >>$(OUTS)
done
""",
visibility = ["//visibility:public"],
)

genrule(
name = "index",
srcs = [
"templates/index.html",
":metadata",
],
outs = ["index.html"],
cmd = """\
$(execpath @stackage-exe//pandoc) \
-V path_prefix=/ \
-f markdown \
-t html \
-s \
--template=$(execpath :templates/index.html) \
--metadata=title:"Amazonka" \
--metadata-file=$(execpath :metadata) \
-o $(OUTS)
""",
tools = ["@stackage-exe//pandoc"],
)

pkg_files(
name = "stylesheets",
srcs = glob(["stylesheets/*.css"]),
strip_prefix = strip_prefix.from_pkg(),
)

pkg_files(
name = "fonts",
srcs = glob(["fonts/*.woff"]),
strip_prefix = strip_prefix.from_pkg(),
)

pkg_files(
name = "package_docs",
srcs = [
":docs",
],
prefix = "",
strip_prefix = strip_prefix.from_pkg(),
)

pkg_tar(
name = "bundle",
srcs = [
":fonts",
":index",
":package_docs",
":stylesheets",
],
)

py_binary(
name = "serve",
srcs = ["serve.py"],
args = ["$(rootpath :bundle)"],
data = [":bundle"],
)
31 changes: 0 additions & 31 deletions docs/config.toml

This file was deleted.

4 changes: 0 additions & 4 deletions docs/content/_index.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/content/docs/getting-started.md

This file was deleted.

Binary file added docs/fonts/Lato-Black.woff
Binary file not shown.
Binary file added docs/fonts/Lato-Bold.woff
Binary file not shown.
Binary file added docs/fonts/Lato-BoldItalic.woff
Binary file not shown.
Binary file added docs/fonts/Lato-Italic.woff
Binary file not shown.
Binary file added docs/fonts/Lato-Regular.woff
Binary file not shown.
Binary file added docs/fonts/Lato-Semibold.woff
Binary file not shown.
Binary file added docs/fonts/Lato-SemiboldItalic.woff
Binary file not shown.
37 changes: 0 additions & 37 deletions docs/layouts/index.html

This file was deleted.

Empty file removed docs/layouts/partials/favicon.html
Empty file.
19 changes: 19 additions & 0 deletions docs/serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

import http.server
import socketserver
import sys
import tempfile
import tarfile

with tempfile.TemporaryDirectory() as root:
with tarfile.TarFile(sys.argv[1], "r") as archive:
archive.extractall(root)

class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super(Handler, self).__init__(*args, directory=root, **kwargs)

with socketserver.TCPServer(("127.0.0.1", 0), Handler) as httpd:
print("http://%s:%s" % httpd.server_address)
httpd.serve_forever()
1 change: 0 additions & 1 deletion docs/static/CNAME

This file was deleted.

3 changes: 0 additions & 3 deletions docs/static/css/custom.css

This file was deleted.

68 changes: 68 additions & 0 deletions docs/stylesheets/fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-Light.woff') format('woff');
font-weight: 300;
font-style: normal;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-LightItalic.woff') format('woff');
font-weight: 300;
font-style: italic;
}
@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-Black.woff') format('woff');
font-weight: 900;
font-style: normal;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-BlackItalic.woff') format('woff');
font-weight: 900;
font-style: italic;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-Bold.woff') format('woff');
font-weight: bold;
font-style: normal;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-BoldItalic.woff') format('woff');
font-weight: bold;
font-style: italic;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-Semibold.woff') format('woff');
font-weight: 500;
font-style: normal;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-SemiboldItalic.woff') format('woff');
font-weight: 500;
font-style: italic;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-Italic.woff') format('woff');
font-weight: normal;
font-style: italic;
}

@font-face {
font-family: 'Lato';
src: url('../fonts/Lato-Regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}
1 change: 1 addition & 0 deletions docs/stylesheets/highlight.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e4583a6

Please sign in to comment.