From 308e32325484be08ad0ece008677c4547a95e908 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 19 Sep 2024 12:07:07 -0500 Subject: [PATCH] add api docs --- .github/workflows/docs.yml | 45 ++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + config.nims | 20 ++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..80cb8c9 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,45 @@ +name: GitHub Pages + +on: + push: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v4 + + - uses: jiro4989/setup-nim-action@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docs + run: nim docs + + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: ./public + + deploy: + needs: build + + permissions: + pages: write + id-token: write + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 + diff --git a/.gitignore b/.gitignore index 8b8da25..bef2acd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ tests/* nimble.develop nimble.paths nimbledeps +public/ diff --git a/config.nims b/config.nims index a1bd7b3..1bc96ba 100644 --- a/config.nims +++ b/config.nims @@ -1,7 +1,25 @@ +import std/[os, strformat, strutils] + task test, "run tests": selfExec "r tests/tbbansi.nim" task develop, "install cligen for development": exec "nimble install -l 'cligen@1.7.5'" ---path:"./nimbledeps/pkgs2/cligen-1.7.5-f3ffe7329c8db755677d3ca377d02ff176cec8b1" +task docs, "Deploy doc html + search index to public/ directory": + let + deployDir = getCurrentDir() / "public" + pkgName = "hwylterm" + srcFile = getCurrentDir() / fmt"src/{pkgName}.nim" + gitUrl = fmt"https://github.com/daylinmorgan/{pkgName}" + selfExec fmt"doc --index:on --git.url:{gitUrl} --git.commit:v{version} --outdir:{deployDir} --project {srcFile}" + withDir deployDir: + mvFile(pkgName & ".html", "index.html") + for file in walkDirRec(".", {pcFile}): + # As we renamed the file, we need to rename that in hyperlinks + exec(r"sed -i -r 's|$1\.html|index.html|g' $2" % [pkgName, file]) + # drop 'src/' from titles + exec(r"sed -i -r 's/<(.*)>src\//<\1>/' $1" % file) + +when withDir(thisDir(), system.dirExists("nimbledeps")): + --path:"./nimbledeps/pkgs2/cligen-1.7.5-f3ffe7329c8db755677d3ca377d02ff176cec8b1"