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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! Maps a source `.md` path to the two things it determines: where its HTML is
//! written, and the URL that serves it.
//!
//! These are one decision, not two. Splitting them is how a generator ends up
//! advertising a URL nothing is written to — so both come out of [`route`] together,
//! and every caller that needs one takes the other from the same call.
use OsStr;
use ;
/// The file name that a server serves for a bare directory request.
const DIRECTORY_INDEX: &str = "index.html";
/// The stem of a source file that is already its directory's index.
const INDEX_STEM: &str = "index";
/// The extension every rendered page is written with.
const HTML_EXTENSION: &str = "html";
/// Where a page is written, and the URL path that reaches it.
///
/// `url_relative` is relative to `link_base` and carries no leading slash;
/// [`crate::page::page_url`] joins the two.
pub
/// Routes `relative_md` — a `.md` path relative to `input_dir` — under the configured
/// URL style.
///
/// With `pretty_urls` off, `guide/setup.md` is written to `guide/setup.html` and
/// served at `guide/setup.html`. With it on, the same source is written to
/// `guide/setup/index.html` and served at `guide/setup/`, which resolves on any server
/// that serves a directory's `index.html` — every static host does.
///
/// The trailing slash is not decoration. A directory index requested without one is
/// not the canonical URL for that page: servers answer it with a 301 to the slashed
/// form (mini-static does, and so do nginx, Apache and GitHub Pages), because the
/// unslashed form resolves the page's relative links against its *parent* directory.
/// Advertising the slashed URL is what makes every internal link and `data.json` entry
/// land in one hop instead of two, and keeps one page from having two addresses.
///
/// A source file already named `index.md` is its directory's index in both styles, so
/// it keeps its own name rather than gaining a second level: `guide/index.md` is
/// written to `guide/index.html`, never `guide/index/index.html`. Under `pretty_urls`
/// it is served as the directory itself (`guide/`), which is what makes a section
/// landing page possible.
pub
/// Rewrites a relative `something.md` link destination to match [`route`]'s URLs.
///
/// Operates on the destination as written in the document — which may be relative
/// (`../guide/setup.md`) — rather than on a path relative to `input_dir`, so it can
/// only apply the same suffix rule, not resolve the target. That is enough: the rule
/// depends on the file's own name, and a relative prefix passes through untouched.
pub
/// Marks a URL path as naming a directory rather than a file, by ensuring it ends in
/// exactly one `/`.
///
/// An empty path is left empty: it is already the base itself, which
/// [`crate::page::join_url`] renders with the separating slash. Adding one here would
/// produce `//`.
/// Renders a path as a URL path: `/`-separated regardless of the host platform.
/// Drops the final `/`-separated segment, leaving the directory that contained it.
///
/// A single-segment path becomes `""` — the site root relative to `link_base`, which
/// [`crate::page::join_url`] renders as the base itself with a trailing slash.