Skip to content

Commit a728b9e

Browse files
authored
update and add more docs to illustrate DemoCards (#69)
Except for some documentation updates, this PR also introduces several new things: * a DemoCards workflow image * tricks that I used a lot when writing * new section: folder manipulation
1 parent 5be3f43 commit a728b9e

19 files changed

+511
-229
lines changed

README.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,44 @@ _Let's focus on writing demos_
1111
## Overview
1212

1313
* a plugin package to `Documenter.jl` to manage all your demos.
14+
* folder structure is the demo structure.
1415
* minimal configuration.
15-
* all demos can be tested by CI.
16+
* CI friendly
1617
* support demos in markdown and julia format.
1718

18-
The philosophy of DemoCards is "folder structure is structure of demos"; organizing folders and files in
19-
the following way, then `DemoCards.jl` will help manage the layouts of the index page.
19+
![democards workflow](docs/quickstart/assets/democards_workflow.png)
20+
21+
The philosophy of DemoCards is "folder structure is the structure of demos"; organizing folders and files in
22+
the a structural way, then `DemoCards.jl` will help manage how you navigate through the pages.
23+
24+
```text
25+
examples
26+
├── part1
27+
│ ├── assets
28+
│ ├── demo_1.md
29+
│ ├── demo_2.md
30+
│ └── demo_3.md
31+
└── part2
32+
├── demo_4.jl
33+
└── demo_5.jl
34+
```
35+
36+
DemoCards would understand it in the following way:
2037

2138
```text
22-
docs/demos/simplest_demopage
23-
└── examples
24-
├── part1
25-
│ ├── assets
26-
│ ├── demo_1.md
27-
│ ├── demo_2.md
28-
│ └── demo_3.md
29-
└── part2
30-
├── assets
31-
├── demo_4.jl
32-
└── demo_5.jl
39+
# Examples
40+
## Part1
41+
demo_1.md
42+
demo_2.md
43+
demo_3.md
44+
## Part2
45+
demo_4.jl
46+
demo_5.jl
3347
```
3448

3549
Read the [Quick Start](https://johnnychen94.github.io/DemoCards.jl/stable/democards/quickstart/index.html) for more instructions.
3650

37-
# Caveat Emptor
51+
## Caveat Emptor
3852

3953
The use of this package heavily relies on [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl),
4054
[Literate.jl](https://github.com/fredrikekre/Literate.jl), [Mustache.jl](https://github.com/jverzani/Mustache.jl)

docs/make.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ makedocs(format = format,
1919
"Home" => "index.md",
2020
quickstart,
2121
"Concepts" => "concepts.md",
22-
"Advanced Usages" => [
23-
"Preview only one demo" => "preview.md",
24-
],
22+
"Partial build" => "preview.md",
23+
"Structure manipulation" => "structure.md",
2524
"Theme Gallery" => [
2625
themeless_demopage,
2726
grid_demopage,
91.3 KB
Loading

docs/quickstart/index.md

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,116 +6,124 @@ This section describes how you can set up your demos easily in _five lines of co
66

77
The rules of demo management are super simple:
88

9-
* you need one demo page to hold all the demo files
10-
* a demo page has several demo sections
9+
* you need one demo page (folder) to hold all the demo files
10+
* a demo page has several demo sections (subfolders)
1111
* a demo section either
1212
* has other demo sections as nested subsections, or,
13-
* has the demo files
13+
* has the demo files (`.md`, `.jl`)
1414

1515
In the following example:
1616

17-
* we have one demo page: "quickstart" ---> The current page you're looking at
18-
* "quickstart" has one demo section: "usage example"
19-
* "usage example" has two demo subsections: "basics" and "julia_demos"
20-
* "basics" section holds all markdown demos
21-
* "julia_demos" section holds all julia demos
22-
* "assets" folders are ignored by `DemoCards.jl`
23-
* "index.md" is where all demo cards are organized in (aka page template)
24-
* "config.json" are configuration files (there're many)
17+
* we have one demo page: `"quickstart"` ---> The current page you're looking at
18+
* `"quickstart"` has one demo section: `"usage example"`
19+
* `"usage example"` has two demo subsections: `"basics"` and `"julia_demos"`
20+
* `"basics"` section holds all markdown demos
21+
* `"julia_demos"` section holds all julia demos
22+
* `"assets"` folders are ignored by `DemoCards.jl`
23+
* `"index.md"` is where all demo cards are organized in (aka page template)
24+
* `"config.json"` are configuration files (there are many of them!)
2525

2626
```text
2727
docs/quickstart
28+
├── config.json
2829
├── index.md
2930
└── usage_example
3031
├── basics
3132
│ ├── assets
3233
│ ├── config.json
3334
│ ├── configure_card.md
3435
│ ├── configure_sec_and_page.md
36+
│ ├── hidden_card.jl
37+
│ ├── hide_your_card_from_index.md
3538
│ └── simple_markdown_demo.md
3639
├── config.json
3740
└── julia_demos
3841
├── 1.julia_demo.jl
3942
├── 2.cover_on_the_fly.jl
40-
└── assets
43+
├── assets
44+
└── config.json
4145
```
4246

43-
```@setup simplest_demopage
44-
using DemoCards
45-
using DemoCards: DemoPage
46-
```
47-
48-
_Democards_ can read the demo structure from your folder structure:
47+
This is the core idea, as long as you organize your folder in a structural way, DemoCards will read
48+
and process your demos to map your folder structure.
4949

5050
```@repl simplest_demopage
51-
cd("../../../..") do
52-
DemoPage("docs/quickstart")
51+
using DemoCards
52+
cd(pkgdir(DemoCards)) do
53+
DemoCards.DemoPage("docs/quickstart")
5354
end
5455
```
5556

5657
## Deploy your demo page
5758

58-
Deployment is also very simple:
59+
![democards workflow](assets/democards_workflow.png)
60+
61+
The above image is the workflow of `DemoCards`. The deployment would be pretty easy:
5962

60-
1. load a theme using `cardtheme`
61-
2. create a demopage using `makedemos`
62-
3. pass the results to `Documenter.jl`
63-
4. postprocess demos generated by Documenter
63+
1. pass your demos to `makedemos`, so that they're preprocessed before passing into `Documenter.jl`
64+
2. generate the entire documentation using `Documenter.makedocs`
65+
3. post process the generated demos using callbacks.
6466

6567
```julia
66-
# 1. generate a DemoCard theme
67-
templates, theme = cardtheme("grid")
68+
# 1. generate demo files
69+
demopage, postprocess_cb, demo_assets = makedemos("demos") # this is the relative path to docs/
6870

69-
# 2. generate demo files
70-
demopage, postprocess_cb = makedemos("demos", templates) # relative path to docs/
71+
# if there are generated css assets, pass it to Documenter.HTML
72+
assets = []
73+
isnothing(demo_assets) || (push!(assets, demo_assets))
7174

72-
# 3. normal Documenter usage
73-
format = Documenter.HTML(assets = [theme, ])
75+
# 2. normal Documenter usage
76+
format = Documenter.HTML(assets = assets)
7477
makedocs(format = format,
7578
pages = [
7679
"Home" => "index.md",
7780
demopage,
7881
],
7982
sitename = "Awesome demos")
8083

81-
# 4. postprocess after makedocs
84+
# 3. postprocess after makedocs
8285
postprocess_cb()
8386
```
8487

88+
In this example, there are three returned objects from `makedemos`:
89+
90+
* `demopage`: this is the relative path to the generated demos (typically in `src/democards`), you
91+
can pass it to `makedocs`'s `pages`.
92+
* `postprocess_cb`: this is the callback function that you'll need to call after `makedocs`.
93+
* `demo_assets`: if available, it is the path to css file which you could pass to `Documenter.HTML`
94+
as style assets. If no theme is configured for your page, it will be `nothing.
8595

8696
After it's set up, you can now focus on contributing more demos and leave
8797
other works to `DemoCards.jl`.
8898

89-
Here's the generated democards! You can read it one by one to get how things are managed in `DemoCards.jl`.
99+
🎉 The following example grids are generated using `DemoCards`! You can read them one by one for
100+
advanced configuration helps. Or you could read the [Concepts](@ref concepts) page first to get
101+
better understanding about the DemoCards type system.
90102

91103
---
92104

93105
{{{democards}}}
94106

95107
---
96108

97-
Actually, this exact page you're reading is generated by `DemoCards.jl`, which we call _the index
98-
page_ of demos. An index page always have cover images, that could sometimes be undesired. In this
99-
case, you could choose to not generate the index page, and use the Documenter's sidebar for
100-
navigation. For example, the "Theme: None" section in "Theme Gallery" is generated by the following
101-
setup:
109+
The page you are reading right now is the generated index page of demos. An index page always have
110+
cover images for the demos. An index page is only generated if you configure the `theme` option in
111+
your page config file (e.g., `docs/quickstart/config.json`):
102112

103-
```julia
104-
# 1. generate demo files
105-
# If you don't pass the templates for index page, then it won't be generated
106-
demopage, postprocess_cb = makedemos("demos")
113+
```json
114+
{
115+
"theme": "grid"
116+
}
117+
```
107118

108-
# 2. normal Documenter usage
109-
makedocs(format = Documenter.HTML(),
110-
pages = [
111-
"Home" => "index.md",
112-
demopage,
113-
],
114-
sitename = "Awesome demos")
119+
There are three themes available now:
115120

116-
# 3. postprocess after makedocs
117-
postprocess_cb()
118-
```
121+
* `"nothing"`(default): index page and associated assets will not be generated, instead, it will use
122+
the sidebar generated by Documenter.jl to navigate through pages. This is the default option when
123+
you doesn't configure `"theme"`.
124+
* `"grid"` and `"list"`: an index page and associated cover images are generated
125+
126+
Please check the "Theme Gallery" part for a preview of these themes.
119127

120128
## What DemoCards.jl does
121129

@@ -124,8 +132,9 @@ The pipeline of [`makedemos`](@ref DemoCards.makedemos) is:
124132
1. analyze the structure of your demo folder and extracts supplementary configuration information
125133
2. copy "`assets`" folder without processing
126134
3. preprocess demo files and save it
127-
4. process and save cover images
128-
5. generate a postprocessing callback function
135+
4. (optional) process and save cover images
136+
5. (optional) generate index page
137+
6. generate a postprocessing callback function
129138

130139
Since all files are generated to `docs/src`, the next step is to leave everything else
131140
to `Documenter.jl` 💯
@@ -140,9 +149,8 @@ to `Documenter.jl` 💯
140149
For advanced usage of `DemoCards.jl`, you need to understand the core [concepts](@ref concepts) of it.
141150

142151
!!! warning
143-
144152
Currently, there's no guarantee that this function works for untypical
145-
documentation folder structure. By the name **typical**, it is:
153+
documentation folder structure. By the word **typical**, it is:
146154

147155
```julia
148156
.

docs/quickstart/usage_example/basics/configure_card.md

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,50 @@ date: 2020-09-13
77
description: This demo show you how to pass additional meta info of card to DemoCards.jl
88
---
99

10-
Besides the meta info extracted from your demo contents, `DemoCards.jl` also
11-
reads the YAML format frontmatter, for example, this demo uses the following
12-
frontmatter:
10+
This page is generated from a markdown file. In `DemoCards.jl`'s type system, it is called
11+
[`MarkdownDemoCard`](@ref DemoCards.MarkdownDemoCard) whose contents are written in the markdown
12+
format.
13+
14+
The markdown files are almost directly passed to `Documenter.jl`, check the
15+
[syntax of Documenter.jl](https://juliadocs.github.io/Documenter.jl/stable/man/syntax/)
16+
if you are unfamiliar with the Julia flavor markdown syntax.
17+
18+
DemoCards extracts potential information from the file to build the index page, e.g., name, title,
19+
reference id, cover image file/URL. If that's not available, then you would need to configure them
20+
by adding a [YAML format front matter](https://jekyllrb.com/docs/front-matter/).
21+
22+
Supported YAML keywords are list as follows:
23+
24+
* `cover`: an URL or a relative path to the cover image. If not configured, it would use the DemoCard logo.
25+
* `description`: a multi-line description to this file, will be displayed when the demo card is hovered.
26+
* `id`: specify the `id` tag for cross-references.
27+
* `title`: one-line description to this file, will be displayed under the cover image.
28+
* `author`: author name. If there are multiple authors, split them with semicolon `;`.
29+
* `date`: any string contents that can be passed to `Dates.DateTime`.
30+
* `hidden`: whether this card is shown in the layout of index page.
31+
32+
!!! tip
33+
All these YAML configs are optional. If specified, it has higher priority over the meta info
34+
extracted from the demo contents. For example, if you don't like the inferred demo title, then
35+
specify one explicitly in the YAML frontmatter.
36+
37+
Of course, you have to make sure the `---` flag shows at the first line of the markdown file,
38+
otherwise DemoCards would just read them as normal contents.
39+
40+
For example, the markdown file of this page uses the following frontmatter:
1341

1442
```markdown
1543
---
1644
title: Configure your card
17-
cover: assets/democards.png
45+
cover: assets/logo.svg
1846
id: configure_your_card
1947
author: Johnny Chen
2048
date: 2020-09-13
2149
description: This demo show you how to pass additional meta info of card to DemoCards.jl
22-
2350
---
24-
```
25-
26-
!!! tip
27-
All these YAML configs are optional. If specified, it has higher priority over the meta info
28-
extracted from the demo contents. For example, if you don't like the inferred demo title, then
29-
specify one explicitly in the YAML frontmatter.
3051

31-
Of course, you have to make sure the `---` flag shows at the first line of the markdown file,
32-
otherwise DemoCards would just read them as normal contents.
33-
34-
The rules are simple:
52+
```
3553

36-
* `author` and `date` badges will only be added if you configure them.
37-
* If there are multiple authors, they could be splitted by semicolon `;`. For example, `author:
38-
Jane Doe; John Roe` would generate two author badges.
39-
* there are two valid `cover` options:
40-
* a local file specified by relative path to the current file, or,
41-
* an image file specified by http(s) URL.
54+
As you can see, if configured, there will be badges for `author` and `date` info. If there are
55+
multiple authors, they could be splitted by semicolon `;`. For example, `author: Jane Doe; John Roe`
56+
would generate two author badges.

docs/quickstart/usage_example/basics/configure_sec_and_page.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Configure your section and page
33
cover: assets/logo.svg
44
---
55

6-
This demo shows you how to manipulate your demo sections.
6+
This demo shows you how to configure your demo page and sections.
77

88
By default, a demo section takes the folder name as its section title, and it
99
takes the file orders as its card orders, which can be unsatisfying in many cases.
@@ -33,8 +33,8 @@ page. For example:
3333
}
3434
```
3535

36-
If not specified, `template` is `"index.md"` if that exists, otherwise, it is a clean minimal
37-
template generated by DemoCards.
36+
If `template` is not specified, `"index.md"` will be used if available, otherwise, it will use a
37+
blank template generated by DemoCards.
3838

3939
There are three possible options for `theme`:
4040

docs/quickstart/usage_example/basics/hide_your_card_from_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
---
22
title: Hide your card from page index layout
33
description: This demo shows you how to hide your card in page layout.
4+
hidden: false
45
---
56

7+
[![](https://img.shields.io/badge/jump%20to-a%20hidden%20demo-blue)](@ref hidden_card)
8+
69
There are cases that you want to hide one card in the generated page layout and only provide the
710
entrance via reflink. For example, you have multiple version of demos and you only want to set the
811
latest one as the default and provide legacy versions as reflink in the latest page.

0 commit comments

Comments
 (0)