-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimise project structure and add new footer local app
- Loading branch information
Showing
13 changed files
with
166 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Footer | ||
|
||
The footer app is useful for displaying copyright information, privacy policy, and other legal information. It supports **markdown** syntax so that you can easily customize the message. | ||
|
||
## Options | ||
|
||
| Option | Description | Required | Default | | ||
| :------ | :--------------------------------- | :------- | :------ | | ||
| message | Footer message, markdown supported | Yes | - - | | ||
|
||
## Example | ||
|
||
<!-- embed ignore begin --> | ||
|
||
```text | ||
{% embed footer message="Copyright © 2024 • Created with ❤️ by [MR-Addict](https://github.com/MR-Addict)" %} | ||
``` | ||
|
||
<!-- embed ignore end --> | ||
|
||
This book's footer is enabled, you can see it at the bottom of this page. | ||
|
||
However, you may want to enable it for the whole book. You can do this by adding below options to `book.toml` file: | ||
|
||
```toml | ||
[preprocessor.embedify] | ||
footer.enable = true | ||
footer.message = "Copyright © 2024 • Created with ❤️ by [MR-Addict](https://github.com/MR-Addict)" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use mdbook::Config; | ||
|
||
pub fn get_config_bool(config: &Config, key: &str) -> bool { | ||
config | ||
.get(format!("preprocessor.embedify.{}", key).as_str()) | ||
.and_then(|v| v.as_bool()) | ||
.unwrap_or(false) | ||
} | ||
|
||
pub fn get_config_string(config: &Config, key: &str, default: &str) -> String { | ||
config | ||
.get(format!("preprocessor.embedify.{}", key).as_str()) | ||
.and_then(|v| v.as_str()) | ||
.unwrap_or(default) | ||
.to_string() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use clap::{Arg, Command}; | ||
use mdbook::preprocess::Preprocessor; | ||
use std::{ | ||
io::{self, IsTerminal}, | ||
process, | ||
}; | ||
|
||
pub struct Cli { | ||
pub cmd: Command, | ||
} | ||
|
||
impl Cli { | ||
pub fn new() -> Self { | ||
let cmd = Command::new("mdbook-embedify") | ||
.version(env!("CARGO_PKG_VERSION")) | ||
.about("A mdbook embed preprocessor that embeds app to your book") | ||
.subcommand( | ||
Command::new("supports") | ||
.arg(Arg::new("renderer").required(true)) | ||
.about("Check whether a renderer is supported by this preprocessor"), | ||
); | ||
|
||
let matches = cmd.clone().get_matches(); | ||
if !matches.args_present() { | ||
if io::stdin().is_terminal() { | ||
cmd.clone().print_help().unwrap(); | ||
process::exit(1); | ||
} | ||
} | ||
|
||
Self { cmd } | ||
} | ||
|
||
pub fn reply_supports(&self, pre: &dyn Preprocessor) { | ||
let matches = self.cmd.clone().get_matches(); | ||
if let Some(sub_args) = matches.subcommand_matches("supports") { | ||
// get the renderer | ||
let renderer = sub_args.get_one::<String>("renderer").unwrap(); | ||
|
||
// signal whether the renderer is supported by exiting with 1 or 0. | ||
if pre.supports_renderer(renderer) { | ||
process::exit(0); | ||
} else { | ||
process::exit(1); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<style> | ||
footer { | ||
text-align: center; | ||
margin-top: 5rem; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
footer p { | ||
margin: 0; | ||
} | ||
</style> | ||
|
||
<footer>{% markdown(message) %}</footer> |