Skip to content

Commit

Permalink
chore: release 0.2.9
Browse files Browse the repository at this point in the history
add more apps to docs and upgrade packages
  • Loading branch information
MR-Addict committed Jul 25, 2024
1 parent b527f4d commit ba2fba1
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 336 deletions.
715 changes: 391 additions & 324 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "mdbook-embedify"
version = "0.2.8"
version = "0.2.9"
edition = "2021"
license = "MIT"
readme = "README.md"
exclude = ["docs/*"]
keywords = ["mdbook", "embed", "plugin"]
keywords = ["mdbook", "embed", "plugin", "preprocessor"]
authors = ["MR-Addict <MR-Addict@qq.com>"]
repository = "https://github.com/MR-Addict/mdbook-embedify"
documentation = "https://mr-addict.github.io/mdbook-embedify"
description = "A rust based mdbook preprocessor plugin that allows you to embed apps to your book, like youtube, codepen and some other apps"

[dependencies]
clap = "4.4.18"
mdbook = "0.4.37"
pulldown-cmark = "0.10.0"
regex = "1.10.3"
rust-embed = "8.2.0"
serde_json = "1.0.111"
clap = "4.5.10"
mdbook = "0.4.40"
pulldown-cmark = "0.11.0"
regex = "1.10.5"
rust-embed = "8.5.0"
serde_json = "1.0.120"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Then you can use `embed` macro to embed an app. The syntax is like this:
![preview](preview.png)

You can see a live demo and more detailed documentation [here](https://mr-addict.github.io/mdbook-embedify).

## 4. More Apps

If you want to add more apps to this preprocessor, you can follow the instructions [here](https://mr-addict.github.io/mdbook-embedify/more-apps.html).
4 changes: 2 additions & 2 deletions docs/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use-default-preprocessors = false
[output.html]
default-theme = "Light"
preferred-dark-theme = "Ayu"
curly-quotes = true
smart-punctuation = true
mathjax-support = true
copy-fonts = true
no-section-label = false
git-repository-url = "https://github.com/mr-addict/mdbook-embedify"
edit-url-template = "https://github.com/mr-addict/mdbook-embedify/edit/main/example/{path}"
edit-url-template = "https://github.com/mr-addict/mdbook-embedify/edit/main/docs/{path}"
additional-css = ["assets/css/patch.css"]

[output.html.print]
Expand Down
3 changes: 2 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

- [Intro](index.md)
- [Usage](usage.md)
- [Ignore Embeds](ignore-embeds.md)
- [Global Embedding](global-embedding.md)
- [Ignore Embeds](ignore-embeds.md)
- [More Apps](more-apps.md)

# Apps

Expand Down
77 changes: 77 additions & 0 deletions docs/src/more-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# More Apps

In this section, I will show you how to add more apps to this preprocessor.

## Create a new app

You may have some other apps that this preprocessor doesn't support. Actually, it's very easy to add a new app based on my custom template engine.

What we need to do is put a new app template in the `templates` folder. The template file name should be the app name.

For example we want to add a new app called `youtube`, and we know that youtube embedding code is using an iframe. It looks like this:

```html
<iframe
allowfullscreen
name="youtube"
loading="lazy"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
style="width: 100%; height: 100%; border: none; aspect-ratio: 16/9; border-radius: 1rem; background: black"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
></iframe>
```

> 💥Attention
>
> You can even add `style` and `js` content to the template file. you can take a look of [scroll-to-top](templates/scroll-to-top.html) example.
## Add options

We want the src youtube `id` and `loading` strategy to be dynamic and loading strategy has default `lazy` value. So we can replace them with placeholders like this:

```html
<iframe
allowfullscreen
name="youtube"
loading="{% raw(loading=lazy) %}"
src="https://www.youtube.com/embed/{% raw(id) %}"
style="width: 100%; height: 100%; border: none; aspect-ratio: 16/9; border-radius: 1rem; background: black"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
></iframe>
```

The placeholder syntax is similar to a **function call** in programming languages.

Which `raw` means the value will not be changed. Now the preprocessor supports two functions, `raw` and `markdown`. `markdown` call will treat the value as markdown content and render it to be html. This call is used in `footer` and `announcement-banner` apps. And inner value will be the `key`, if the key has a `default` value, we put an equal sign and the default value after the key.

## Build the project

After build the project, the new app will be automatically added to the preprocessor binary.

```sh
cargo build --release
```

And you can use it in your book:

<!-- embed ignore begin -->

```text
{% embed youtube id="dQw4w9WgXcQ" loading="eager" %}
```

Because the `loading` key has a default value `lazy`, we can omit it.

```text
{% embed youtube id="dQw4w9WgXcQ" %}
```

<!-- embed ignore end -->

If you are using this repository as a template, then you can build your book to see the result by running:

```sh
mdbook build docs
```

That's it. If you have some apps need to be added, you can create a new issue or pull request.
2 changes: 1 addition & 1 deletion docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Installation

There are two ways to install this plugin.
There are two ways to install this preprocessor.

You can install it from crates.io using cargo.

Expand Down
1 change: 1 addition & 0 deletions templates/announcement-banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
text-align: center;
white-space: nowrap;
text-overflow: ellipsis;
text-wrap: balance;
}

.announcement-banner button {
Expand Down

0 comments on commit ba2fba1

Please sign in to comment.