Skip to content

Commit 1234e2e

Browse files
authored
set up Documentation (#35)
1 parent 4cf22fb commit 1234e2e

File tree

7 files changed

+104
-0
lines changed

7 files changed

+104
-0
lines changed

.github/workflows/documentation.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Documentation
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'master'
8+
- 'release-'
9+
tags: '*'
10+
release:
11+
types: [published]
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
julia-version: [1]
19+
os: [ubuntu-latest]
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: julia-actions/setup-julia@latest
23+
with:
24+
version: ${{ matrix.julia-version }}
25+
- name: Cache artifacts
26+
uses: actions/cache@v1
27+
env:
28+
cache-name: cache-artifacts
29+
with:
30+
path: ~/.julia/artifacts
31+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
32+
restore-keys: |
33+
${{ runner.os }}-test-${{ env.cache-name }}-
34+
${{ runner.os }}-test-
35+
${{ runner.os }}-
36+
- name: Install dependencies
37+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
38+
- name: Build and deploy
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
run: julia --project=docs/ docs/make.jl

README-zh-cn.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# LeetCode in Julia - 用 Julia 编写力扣题目
22

3+
[![Documentation][docs-dev-img]][docs-dev-url]
34
[![Unit Test][action-img]][action-url]
45
[![Code Style: Blue][blue-img]][blue-url]
56

@@ -23,3 +24,5 @@
2324
[action-url]: https://github.com/JuliaCN/LeetCode.jl/actions
2425
[blue-img]: https://img.shields.io/badge/code%20style-blue-4495d1.svg
2526
[blue-url]: https://github.com/invenia/BlueStyle
27+
[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg
28+
[docs-dev-url]: https://github.com/JuliaCN/LeetCode.jl/latest

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# LeetCode
22

3+
[![Documentation][docs-dev-img]][docs-dev-url]
34
[![Unit Test][action-img]][action-url]
45
[![Code Style: Blue][blue-img]][blue-url]
56

@@ -22,3 +23,5 @@ A community driven project to provide solutions for LeetCode problems in the Jul
2223
[action-url]: https://github.com/JuliaCN/LeetCode.jl/actions
2324
[blue-img]: https://img.shields.io/badge/code%20style-blue-4495d1.svg
2425
[blue-url]: https://github.com/invenia/BlueStyle
26+
[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg
27+
[docs-dev-url]: https://github.com/JuliaCN/LeetCode.jl/latest

docs/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/problems
2+
/Manifest.toml
3+
/build
4+
/src/democards

docs/Project.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[deps]
2+
DemoCards = "311a05b2-6137-4a5a-b473-18580a3d38b5"
3+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
4+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
5+
LeetCode = "177aac61-66e1-4cb4-9340-6393b6c3fb4c"
6+
7+
[compat]
8+
Documenter = "0.25"
9+
DemoCards = "0.3"

docs/make.jl

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Documenter
2+
using DemoCards
3+
using JSON
4+
5+
root = joinpath(@__DIR__, "..")
6+
page_root = joinpath(root, "docs", "problems")
7+
page_src = joinpath(root, "src", "problems")
8+
page_dest = joinpath(page_root, "id")
9+
10+
# prepare page contents and page meta
11+
if isdir(page_root)
12+
rm(page_root; force=true, recursive=true)
13+
end
14+
mkpath(page_root)
15+
cp(page_src, page_dest; force=true)
16+
rm(joinpath(page_dest, "problems.jl")) # no need to render this
17+
18+
# provide a configuration file to tell DemoCards that we want to use number order instead
19+
# of string order
20+
open(joinpath(page_dest, "config.json"), "w") do io
21+
files = filter(x->x!="config.json", readdir(page_dest))
22+
sort!(files; by=x->parse(Int, split(x, ".")[1]))
23+
JSON.print(io, Dict("title"=>"By ID", "order"=>files))
24+
end
25+
26+
## build docs
27+
28+
# 1. generate demo files
29+
demopage, postprocess_cb = makedemos("problems") # the relative path to docs/
30+
31+
# 2. normal Documenter usage
32+
format = Documenter.HTML(prettyurls=get(ENV, "CI", nothing) == "true")
33+
makedocs(format = format,
34+
pages = [
35+
"Home" => "index.md",
36+
demopage,
37+
],
38+
sitename = "LeetCode")
39+
40+
# 3. postprocess after makedocs
41+
postprocess_cb()

docs/src/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# LeetCode
2+
3+
The solution set to LeetCode problems!

0 commit comments

Comments
 (0)