Add "Suggest an edit" link next to "Git repository"
Includes new configuration option `git-repository-edit-baseurl` for supporting non-GitHub repository layouts.
This commit is contained in:
parent
59073b1084
commit
a6f13ff54d
|
@ -201,6 +201,12 @@ The following configuration options are available:
|
|||
an icon link will be output in the menu bar of the book.
|
||||
- **git-repository-icon:** The FontAwesome icon class to use for the git
|
||||
repository link. Defaults to `fa-github`.
|
||||
- **git-repository-edit-baseurl:** The base url for suggesting an edit
|
||||
to individual pages/chapters of the book. If **git-repository-url** is defined,
|
||||
defaults to **git-repository-url**/blob/master which works for e.g. GitHub.
|
||||
The page source path is appended to this url, e.g. `/src/SUMMARY.md`. So when
|
||||
this or **git-repository-url** is configured an icon link will be output in
|
||||
the menu bar of the book.
|
||||
- **redirect:** A subtable used for generating redirects when a page is moved.
|
||||
The table contains key-value pairs where the key is where the redirect file
|
||||
needs to be created, as an absolute path from the build directory, (e.g.
|
||||
|
|
|
@ -530,6 +530,15 @@ pub struct HtmlConfig {
|
|||
/// is ignored, because our code overrides this field with the value [`LIVE_RELOAD_ENDPOINT`]
|
||||
///
|
||||
/// [`LIVE_RELOAD_ENDPOINT`]: cmd::serve::LIVE_RELOAD_ENDPOINT
|
||||
/// Git repository file edit baseurl, below which e.g. src/SUMMARY.md can
|
||||
/// be viewed/edited
|
||||
/// Defaults to git_repository_url + `/blob/master` if `None` and
|
||||
/// git_repository_url is not `None` - works for e.g. GitHub master branch
|
||||
pub git_repository_edit_baseurl: Option<String>,
|
||||
/// This is used as a bit of a workaround for the `mdbook serve` command.
|
||||
/// Basically, because you set the websocket port from the command line, the
|
||||
/// `mdbook serve` command needs a way to let the HTML renderer know where
|
||||
/// to point livereloading at, if it has been enabled.
|
||||
///
|
||||
/// This config item *should not be edited* by the end user.
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -766,6 +766,16 @@ fn make_data(
|
|||
|
||||
if let Some(ref git_repository_url) = html_config.git_repository_url {
|
||||
data.insert("git_repository_url".to_owned(), json!(git_repository_url));
|
||||
let defaultEditBaseUrl = git_repository_url.to_owned() + "/blob/master";
|
||||
let git_repository_edit_baseurl = match html_config.git_repository_edit_baseurl {
|
||||
Some(ref git_repository_edit_baseurl) => git_repository_edit_baseurl,
|
||||
None => &defaultEditBaseUrl,
|
||||
};
|
||||
data.insert("git_repository_edit_baseurl".to_owned(), json!(git_repository_edit_baseurl));
|
||||
} else {
|
||||
if let Some(ref git_repository_edit_baseurl) = html_config.git_repository_edit_baseurl {
|
||||
data.insert("git_repository_edit_baseurl".to_owned(), json!(git_repository_edit_baseurl));
|
||||
}
|
||||
}
|
||||
|
||||
let git_repository_icon = match html_config.git_repository_icon {
|
||||
|
|
|
@ -152,8 +152,8 @@
|
|||
<i id="git-repository-button" class="fab {{git_repository_icon}}"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{#if git_repository_edit_url}}
|
||||
<a href="{{git_repository_edit_url}}" title="Suggest an edit" aria-label="Suggest an edit">
|
||||
{{#if git_repository_edit_baseurl}}
|
||||
<a href="{{git_repository_edit_baseurl}}/src/{{path}}" title="Suggest an edit" aria-label="Suggest an edit">
|
||||
<i id="git-edit-button" class="fa fa-edit"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
|
|
Loading…
Reference in New Issue