summaryrefslogtreecommitdiff
path: root/.github/workflows/manpages.yml
blob: fc5dae14f7d8dec17346e01b6805d11baa24ef85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Generate man pages

on:
  push:
    paths:
      - "Base/usr/share/man/**"
      - "Meta/Websites/man.serenityos.org/**"

env:
  MAN_DIR: ${{ github.workspace }}/Base/usr/share/man/

jobs:
  convert_using_pandoc:
    runs-on: ubuntu-20.04
    if: always() && github.repository == 'SerenityOS/serenity' && github.ref == 'refs/heads/master'
    steps:
      - uses: actions/checkout@v2
      - uses: r-lib/actions/setup-pandoc@v1
        with:
          pandoc-version: '2.13'
      - name: Prepare output directories
        run: |
          for d in $MAN_DIR*/; do
            dir_name=$(basename "$d")
            section="${dir_name/man}"
            mkdir -p "output/${section}"
          done
      - name: Convert markdown to html
        run: |
          cat << EOF > link-fixup.lua
          function Link(el)
            el.target = string.gsub(el.target, "%.md", ".html") -- fixup .md to .html links
            el.target = string.gsub(el.target, "man", "", 1) -- fixup man1/???.html to 1/???.html links
            return el
          end
          EOF
          find $MAN_DIR -iname '*.md' -type f -exec sh -c '\
            relative_path="$(realpath --relative-to=$MAN_DIR $0)" \
            && stripped_path="${relative_path#man}" \
            && section="${stripped_path%%/*}" \
            && filename="${stripped_path#*/}" \
            && name="${filename%.md}" \
            && pandoc -f gfm -t html5 -s --lua-filter=link-fixup.lua --metadata title="${name}(${section}) - SerenityOS man pages" -o "output/${section}/${name}.html" "${0}" \
          ' {} \;
      - name: Generate man page listings
        run: |
          for d in output/*/; do
            section=$(basename "$d")
            echo "<!DOCTYPE html><html><head><title>Section ${section} - SerenityOS man pages</title></head><body>" > "${d}/index.html"
            for f in $d/*; do
              filename=$(basename "$f")
              name="${filename%.html}"
              if [[ "$filename" == "index.html" ]]; then
                 continue
              fi
              echo "<a href=\"${filename}\"><p>${name}(${section})</p></a>" >> "${d}/index.html"
            done
            echo "</body></html>" >> "$d/index.html"
          done
      - name: Copy pre-made files
        run: |
          cp -R Meta/Websites/man.serenityos.org/* output/
      - name: Deploy to GitHub pages
        uses: JamesIves/github-pages-deploy-action@4.1.1
        with:
          git-config-name: BuggieBot
          git-config-email: buggiebot@serenityos.org
          branch: master
          repository-name: SerenityOS/manpages-website
          token: ${{ secrets.BUGGIEBOT }}
          folder: output