Skip to content

Commit 8afa3b4

Browse files
committed
v0.14.0: virtual pages, template fixes
1 parent eba009f commit 8afa3b4

20 files changed

+210
-133
lines changed

dactyl/dactyl_build.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ def build_all(self, only_page=None):
140140
es_data = {}
141141
matched_only = False
142142
for page in pages:
143+
if page.is_virtual():
144+
logger.debug("skipping virtual page: %s" % page)
145+
continue
146+
143147
if only_page:
144148
if self.match_only_page(only_page, page.data):
145149
matched_only = True
@@ -444,7 +448,7 @@ def assemble_pdf(self, only_page=None):
444448
if not self.config["legacy_prince"]:
445449
args.append('--no-warn-css')
446450

447-
pages = self.target.pages
451+
pages = [p for p in self.target.pages if not p.is_virtual()]
448452
if only_page:
449453
pages = [p for p in pages if self.match_only_page(only_page, p.data)][:1]
450454
if not len(pages):

dactyl/filter_demote_headers.py

+5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ def filter_html(html, mode="html", target={}, **kwargs):
1818
return html
1919

2020
html = html.replace("<h5", "<h6")
21+
html = html.replace("</h5", "</h6")
2122
html = html.replace("<h4", "<h5")
23+
html = html.replace("</h4", "</h5")
2224
html = html.replace("<h3", "<h4")
25+
html = html.replace("</h3", "</h4")
2326
html = html.replace("<h2", "<h3")
27+
html = html.replace("</h2", "</h3")
2428
html = html.replace("<h1", "<h2")
29+
html = html.replace("</h1", "</h2")
2530
return html

dactyl/page.py

+9
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,15 @@ def filter_exports(self):
555555
exported_vals[key] = val
556556
return exported_vals
557557

558+
def is_virtual(self):
559+
"""
560+
Returns True if this is a "virtual" page that does not have a real HTML
561+
output. These types of pages are essentially placeholders for navigation.
562+
"""
563+
if "//" in self.data["html"]:
564+
return True
565+
return False
566+
558567
def filters(self, save=True):
559568
"""
560569
Returns the names of filters to use when processing this page.

dactyl/target.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def load_pages(self):
234234
for p in pages:
235235
if "html" not in p.data.keys():
236236
logger.error("page has no html somehow? %s"%p.data)
237-
if p.data["html"] in html_outs:
237+
if p.data["html"] in html_outs and not p.is_virtual():
238238
recoverable_error(("Repeated output filename '%s'. The earlier "+
239239
"instances will be overwritten") % p.data["html"],
240240
self.config.bypass_errors)

dactyl/templates/children.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{% for child in parent.children %}
2323
{% if child.nav_omit is defined and child.nav_omit %}{# skip pages that are omitted from navigation #}
2424
{% elif ns.count_printed < count_limit %}
25-
<li class="level-{{indent_level}}"><a href="{{target.prefix}}{{child.html}}">{{child.name}}</a>{% if show_blurbs and child.blurb is defined and indent_level == 1%}<p class="blurb child-blurb">{{child.blurb}}</p>{% endif %}</li>
25+
<li class="level-{{indent_level}}"><a href="{{target.prefix}}{{child.html}}">{{child.name}}</a>{% if show_blurbs and child.blurb is defined %}<p class="blurb child-blurb">{{child.blurb}}</p>{% endif %}</li>
2626
{% set ns.count_printed = ns.count_printed + 1 %}
2727
{% if indent_level+1 <= depth_limit %}
2828
{# recursively print descendants #}

dactyl/templates/pdf-cover.html

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
.dactyl-pdf-toc {
1212
page-break-after: always;
1313
}
14+
.level-1 {
15+
margin-left: 1rem;
16+
}
17+
.level-2 {
18+
list-style-type: circle;
19+
margin-left: 2rem;
20+
}
21+
.level-3 {
22+
list-style-type: square;
23+
margin-left: 3rem;
24+
}
1425
.dactyl-pdf-cover .dactyl-pdf-title-area {
1526
position: absolute;
1627
top: 26%;

dactyl/templates/simple.html

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
@media print {
3939
.dactyl-sidebar {display: none;}
40+
.hover_anchor {display:none;}
4041

4142
@page {
4243
@bottom-left {

dactyl/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.14.0a5'
1+
__version__ = '0.14.0'

examples/content/code-highlighting.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
blurb: Dactyl automatically adds syntax highlighting to code blocks.
3+
---
14
# Code Highlighting
25

36
Dactyl automatically adds syntax highlighting to code blocks when it parses Markdown, using the [Pygments](https://pygments.org/)-derived [CodeHilite](https://python-markdown.github.io/extensions/code_hilite/) extension. Parsing the syntax highlighting at compile time like this is faster and less work for readers' computers than in-browser syntax highlighting such as using [highlight.js](https://highlightjs.readthedocs.io/en/latest/api.html). (If you prefer highlight.js's output, though, you can still run it to overwrite Dactyl's syntax highlighting.)

examples/content/frontmatter.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
desc: This file has Jekyll-style frontmatter
3+
categories: ["Tests", "Dactyl ignores categories beyond the first"]
4+
---
5+
# Frontmatter
6+
7+
Frontmatter is a set of YAML keys and values to start a Markdown file, set off by two lines of `---`. For example, this page has the following frontmatter:
8+
9+
```yaml
10+
---
11+
desc: This file has Jekyll-style frontmatter
12+
categories: ["Tests", "Dactyl ignores categories beyond the first"]
13+
---
14+
```
15+
16+
The frontmatter can be referenced by the preprocessor and by templates. For example:
17+
18+
```
19+
> Description: {{"{{"}}currentpage.desc{{"}}"}}
20+
```
21+
22+
Results:
23+
24+
> Description: {{currentpage.desc}}
25+
26+
27+
**Caution:** If you [include](includes.html) a page, the frontmatter of the included page is not available to the including page.

examples/content/includes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Includes Test
1+
# Includes
22

33
This page demonstrates including a file using the [preprocessor's `include` syntax](https://jinja.palletsprojects.com/en/2.11.x/templates/#include). The path to including a file is always relative to the **`content_path`** from the config.
44

examples/content/link-checking.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
html: link-checking.html
3+
parent: features.html
4+
---
5+
# Link Checking
6+
7+
Dactyl includes a link-checking script to automatically detect and report on broken hyperlinks in your generated documentation.
8+
9+
## Usage
10+
11+
First, build some documentation to an output path. Depending on your configuration, you may want to build multiple targets to different output directories before running the link checker.
12+
13+
Then, run the link checker as follows:
14+
15+
```sh
16+
$ dactyl_link_checker
17+
```
18+
19+
This checks all the files in the output directory for links and confirms that any HTTP(S) links, including relative links to other files, are valid. For anchor links, it checks that an element with the correct ID exists in the target file. It also checks that the `src` of all image tags exists.
20+
21+
If there are links that are always reported as broken but you don't want to remove (for example, URLs that block Python's user-agent) you can add them to the `known_broken_links` array in the config.
22+
23+
In quiet mode (`-q`), the link checker still reports in every 30 seconds just so that it doesn't get treated as stalled and killed by continuous integration software (e.g. Jenkins).
24+
25+
To reduce the number of meaningless failure reports (because a particular website happened to be down momentarily while you ran the link checker), if there are any broken remote links, the link checker waits 2 minutes after finishing and then retries those links in case they came back up. (If they did, they're not considered broken for the link checker's final report.)
26+
27+
You can also run the link checker in offline mode (`-o`) to skip any remote links and just check that the files and anchors referenced exist in the output directory.
28+
29+
If you have a page that uses JavaScript or something to generate anchors dynamically, the link checker can't find those anchors (since it doesn't run any JS). You can add such pages to the `ignore_anchors_in` array in your config to skip checking for links that go to anchors in such pages.
30+
31+
## Unusual Link Types
32+
33+
Some unusual types of links that you may encounter in HTML or Markdown include:
34+
35+
- [Protocol relative URL](//dactyl.link/features.html) - these start with `//` and refer to "whatever protocl is being used now". Dactyl assumes HTTPS should work for these URLs.
36+
- [Mailto URL](mailto:[email protected]) - Email addresses. The link checker ignores these and other links that use other URI schemes.
37+
- [Javascript Bookmarklet](javascript:alert%28'A bookmarklet did this'%29) - JavaScript code embedded in the href directly with `javascript:`. The link checker ignores these.
38+
- [Empty anchor](#) - A link to `#`. This type of link is often used to trigger JavaScript events. The link checker considers these invalid for `<img>` paths but OK for `<a>` tags.

examples/content/link-types.md

-12
This file was deleted.

examples/content/virtual-pages.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
category: Features
3+
parent: features.html
4+
---
5+
# Virtual Pages
6+
7+
"Virtual Pages" are placeholders for pages or websites that are not part of the Dactyl site, but that you want to link from within the Dactyl-generated navigation. Dactyl's built-in templates automatically create links to virtual pages in the appropriate places within the navigation.
8+
9+
Dactyl does not build an associated output HTML file for these pages, so they are linked from PDF builds but their contents are not part of the generated PDF. The [link checker](link-checking.html) treats virtual pages the same as other external links, so it checks links _to_ them but not _in_ the virtual pages.
10+
11+
The "Dactyl Homepage" link listed under this page is an example of a Virtual Page. To create a virtual link, add a stanza such as the following to the page array in your config file:
12+
13+
```yaml
14+
- name: Dactyl Homepage
15+
parent: virtual-pages.html
16+
html: https://dactyl.link/
17+
targets:
18+
- everything
19+
```
20+
21+
Specifically, a virtual page is **any page with `//` in its `html` attribute.**
22+
23+
You can also define a virtual page using a `.md` file with [frontmatter](frontmatter.html). For example, you could have a file with the following contents:
24+
25+
```md
26+
---
27+
html: https://dactyl.link/
28+
blurb: This is an example of a virtual page defined by MD frontmatter.
29+
category: Features
30+
parent: virtual-pages.html
31+
---
32+
# Virtual Placeholder
33+
34+
The actual Markdown contents of a "virtual page" are mostly ignored. However, they can be used to provide metadata such as the title and blurb used in navigation on other pages.
35+
```
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
html: https://dactyl.link/
3+
blurb: This is an example of a virtual page defined by MD frontmatter.
4+
category: Features
5+
parent: virtual-pages.html
6+
---
7+
# Virtual Placeholder
8+
9+
The actual Markdown contents of a "virtual page" are mostly ignored. However, they can be used to provide metadata such as the title and blurb used in navigation on other pages.

examples/content/with-frontmatter.md

-18
This file was deleted.

examples/dactyl-config.yml

+37-21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ filter_paths:
88
defaults: &defaults
99
hover_anchors: ""
1010

11+
spelling_file: spelling.txt
12+
1113
targets:
1214
- name: everything
1315
display_name: Dactyl Examples
@@ -28,9 +30,9 @@ targets:
2830
<<: *defaults
2931

3032
pages:
31-
- name: Tests
32-
html: tests-index.html
33-
category: Tests
33+
- name: Features
34+
html: features.html
35+
category: Features
3436
section_header: true
3537
parent: index.html
3638
template: landing.html
@@ -39,57 +41,71 @@ pages:
3941

4042
- md: code-highlighting.md
4143
html: code-highlighting.html
42-
parent: tests-index.html
44+
parent: features.html
4345
targets:
4446
- everything
4547

4648
- md: includes.md
47-
category: Tests
48-
parent: tests-index.html
49+
category: Features
50+
parent: features.html
4951
targets:
5052
- everything
5153

52-
- md: with-frontmatter.md
53-
html: with-frontmatter.html
54-
parent: tests-index.html
54+
- md: frontmatter.md
55+
html: frontmatter.html
56+
parent: features.html
5557
targets:
5658
- everything
5759

5860
- md: cli-vars.md
5961
html: cli-vars.html
60-
parent: tests-index.html
62+
parent: features.html
6163
targets:
6264
- everything
6365

64-
- md: link-types.md
66+
- md: link-checking.md
6567
targets:
6668
- everything
6769

68-
- name: Conditionals Test
69-
category: Tests
70-
md: conditionals.md
71-
parent: tests-index.html
70+
- md: conditionals.md
71+
category: Features
72+
parent: features.html
7273
targets:
7374
- everything
7475
- conditionals
7576

7677
- name: Lists and Code Blocks Demo
77-
category: Tests
78+
category: Features
7879
md: lists-and-codeblocks.md
79-
parent: tests-index.html
80+
parent: features.html
8081
targets:
8182
- everything
8283

8384
- name: GitHub Markdown Compatibility
84-
category: Tests
85+
category: Features
8586
md: gfm-compat.md
86-
parent: tests-index.html
87+
parent: features.html
8788
targets:
8889
- everything
8990

9091
- md: header_stress_test.md
91-
category: Tests
92-
parent: tests-index.html
92+
category: Features
93+
parent: features.html
94+
targets:
95+
- everything
96+
97+
- md: virtual-pages.md
98+
targets:
99+
- everything
100+
101+
- name: Dactyl Homepage
102+
parent: virtual-pages.html
103+
html: https://dactyl.link/#
104+
blurb: This is a placeholder that shows up in navigation but does not have an actual output file. Use this if you want to link to external resources at a specific place in your navigation.
105+
targets:
106+
- everything
107+
108+
- md: virtual-placeholder.md
93109
targets:
94110
- everything
95111

examples/spelling.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
frontmatter

examples/template_assets/dactyl-buttonize.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
a.button {
1+
/* Stand-alone CSS for use with the buttonize filter. Skip if you use
2+
Bootstrap. */
3+
a.btn-primary {
24
color: white;
35
background: #0000EE;
46
text-decoration: none;

0 commit comments

Comments
 (0)