Skip to content

Commit

Permalink
feat: expose loading api to all third apps that using iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Addict committed Feb 15, 2024
1 parent 04fdf10 commit e43c3fc
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Then you can use `embed` macro to embed an app. The syntax is like this:
**options** are key-value based array seperated by space and its value must be wrapped by **quotes**. For example:

```text
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" %}
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" loading="lazy" %}
```

## 3. Examples
Expand Down
10 changes: 1 addition & 9 deletions example/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ multilingual = false
src = "src"
title = "Mdbook Embedify"

[rust]
edition = "2021"

[build]
build-dir = "book"
create-missing = false
Expand All @@ -32,12 +29,6 @@ enable = true
enable = true
level = 1

[output.html.playground]
editable = true
copyable = true
copy-js = true
line-numbers = true

[output.html.search]
enable = true
limit-results = 30
Expand Down Expand Up @@ -71,3 +62,4 @@ giscus.category-id = "DIC_kwDOLCxX0c4CdGx-"
giscus.reactions-enabled = "1"
giscus.theme = "light"
giscus.lang = "en"
giscus.loading = "eager"
1 change: 1 addition & 0 deletions example/src/global-embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ giscus.category-id = "DIC_kwDOLCxX0c4CdGx-"
giscus.reactions-enabled = "1"
giscus.theme = "light"
giscus.lang = "en"
giscus.loading = "eager"
```

You can see more details about each app at its own page.
2 changes: 1 addition & 1 deletion example/src/ignore-embeds.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For example:
```text
<!-- embed ignore begin -->
{% embed youtube id="DyTCOwB0DVw" %}
{% embed youtube id="DyTCOwB0DVw" loading="lazy" %}
<!-- embed ignore end -->
```
Expand Down
11 changes: 6 additions & 5 deletions example/src/third-party/bilibili.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

## Options

| Option | Description | Required | Default |
| :----- | :---------- | :------- | :------ |
| id | Video ID | Yes | - - |
| Option | Description | Required | Default |
| :------ | :----------- | :------- | :------ |
| id | Video ID | Yes | - - |
| loading | Loading type | No | lazy |

## Example

<!-- embed ignore begin -->

```text
{% embed bilibili id="BV1uT4y1P7CX" %}
{% embed bilibili id="BV1uT4y1P7CX" loading="lazy" %}
```

<!-- embed ignore end -->

{% embed bilibili id="BV1uT4y1P7CX" %}
{% embed bilibili id="BV1uT4y1P7CX" loading="lazy" %}
17 changes: 9 additions & 8 deletions example/src/third-party/codepen.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

## Options

| Option | Description | Required | Default |
| :----- | :------------ | :------- | :------ |
| user | username | Yes | - - |
| slug | Project slug | Yes | - - |
| height | Iframe height | No | 600 |
| theme | Iframe theme | No | dark |
| Option | Description | Required | Default |
| :------ | :------------ | :------- | :------ |
| user | username | Yes | - - |
| slug | Project slug | Yes | - - |
| height | Iframe height | No | 600 |
| theme | Iframe theme | No | dark |
| loading | Loading type | No | lazy |

## Example

<!-- embed ignore begin -->

```text
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" %}
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" loading="lazy" %}
```

<!-- embed ignore end -->

{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" %}
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" loading="lazy" %}
13 changes: 7 additions & 6 deletions example/src/third-party/codesandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

## Options

| Option | Description | Required | Default |
| :----- | :----------- | :------- | :------ |
| id | Project ID | Yes | - - |
| theme | Iframe theme | No | dark |
| Option | Description | Required | Default |
| :------ | :----------- | :------- | :------ |
| id | Project ID | Yes | - - |
| theme | Iframe theme | No | dark |
| loading | Loading type | No | lazy |

## Example

<!-- embed ignore begin -->

```text
{% embed codesandbox id="ke8wx" theme="light" %}
{% embed codesandbox id="ke8wx" theme="light" loading="lazy" %}
```

<!-- embed ignore end -->

{% embed codesandbox id="ke8wx" theme="light" %}
{% embed codesandbox id="ke8wx" theme="light" loading="lazy" %}
4 changes: 3 additions & 1 deletion example/src/third-party/giscus.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
| reactions-enabled | Enable reactions | No | 1 |
| theme | Theme | No | light |
| lang | Language | No | en |
| loading | Loading type | No | lazy |

## Example

<!-- embed ignore begin -->

```text
{% embed giscus repo="MR-Addict/mdbook-embedify" repo-id="R_kgDOLCxX0Q" category="General" category-id="DIC_kwDOLCxX0c4CdGx-" theme="light" %}
{% embed giscus repo="MR-Addict/mdbook-embedify" repo-id="R_kgDOLCxX0Q" category="General" category-id="DIC_kwDOLCxX0c4CdGx-" theme="light" loading="lazy" %}
```

<!-- embed ignore end -->
Expand All @@ -37,6 +38,7 @@ giscus.category-id = "DIC_kwDOLCxX0c4CdGx-"
giscus.reactions-enabled = "1"
giscus.theme = "light"
giscus.lang = "en"
giscus.loading = "eager"
```

## Refuse to Connect
Expand Down
13 changes: 7 additions & 6 deletions example/src/third-party/stackblitz.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

## Options

| Option | Description | Required | Default |
| :----- | :----------- | :------- | :------ |
| id | Project ID | Yes | - - |
| theme | Iframe theme | No | dark |
| Option | Description | Required | Default |
| :------ | :----------- | :------- | :------ |
| id | Project ID | Yes | - - |
| theme | Iframe theme | No | dark |
| loading | Loading type | No | lazy |

## Example

<!-- embed ignore begin -->

```text
{% embed stackblitz id="vitejs-vite-y8mdxg" theme="light" %}
{% embed stackblitz id="vitejs-vite-y8mdxg" theme="light" loading="lazy" %}
```

<!-- embed ignore end -->

{% embed stackblitz id="vitejs-vite-y8mdxg" theme="light" %}
{% embed stackblitz id="vitejs-vite-y8mdxg" theme="light" loading="lazy" %}
11 changes: 6 additions & 5 deletions example/src/third-party/youtube.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

## Options

| Option | Description | Required | Default |
| :----- | :---------- | :------- | :------ |
| id | Video ID | Yes | - - |
| Option | Description | Required | Default |
| :------ | :----------- | :------- | :------ |
| id | Video ID | Yes | - - |
| loading | Loading type | No | lazy |

## Example

<!-- embed ignore begin -->

```text
{% embed youtube id="DyTCOwB0DVw" %}
{% embed youtube id="DyTCOwB0DVw" loading="lazy" %}
```

<!-- embed ignore end -->

{% embed youtube id="DyTCOwB0DVw" %}
{% embed youtube id="DyTCOwB0DVw" loading="lazy" %}
2 changes: 1 addition & 1 deletion example/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The basic syntax is like this:
For example:

```text
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" %}
{% embed codepen user="MR-Addict" slug="NWBOqKw" height="600" theme="dark" loading="lazy" %}
```

<!-- embed ignore end -->
Expand Down
2 changes: 2 additions & 0 deletions src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn render_giscus(config: &Config) -> String {
let reactions_enabled = cfg::get_config_string(config, "giscus.reactions-enabled", "1");
let theme = cfg::get_config_string(config, "giscus.theme", "light");
let lang = cfg::get_config_string(config, "giscus.lang", "en");
let loading = cfg::get_config_string(config, "giscus.loading", "lazy");

// render the template
let options = vec![
Expand All @@ -92,6 +93,7 @@ fn render_giscus(config: &Config) -> String {
("reactions-enabled".to_string(), reactions_enabled),
("theme".to_string(), theme),
("lang".to_string(), lang),
("loading".to_string(), loading),
];
utils::render_template("giscus", &options)
}
Expand Down
2 changes: 1 addition & 1 deletion templates/bilibili.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<iframe
allowfullscreen
loading="lazy"
name="bilibili"
loading="{% raw(loading=lazy) %}"
src="https://player.bilibili.com/player.html?bvid={% raw(id) %}&danmaku=0"
style="width: 100%; height: 100%; border: none; aspect-ratio: 16/9; border-radius: 1rem; background: black"
></iframe>
2 changes: 1 addition & 1 deletion templates/codepen.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<iframe
allowfullscreen
loading="lazy"
name="codepen"
loading="{% raw(loading=lazy) %}"
height="{% raw(height=600) %}"
style="width: 100%; border: none; border-radius: 1rem; background: black"
src="https://codepen.io/{% raw(user) %}/embed/{% raw(slug) %}?default-tab=result&theme-id={% raw(theme=dark) %}"
Expand Down
2 changes: 1 addition & 1 deletion templates/codesandbox.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<iframe
loading="lazy"
name="sandbox"
loading="{% raw(loading=lazy) %}"
src="https://codesandbox.io/embed/{% raw(id) %}?&theme={% raw(theme=dark) %}"
style="width: 100%; height: 100%; border: none; aspect-ratio: 16/9; border-radius: 1rem; background: black"
></iframe>
2 changes: 1 addition & 1 deletion templates/giscus.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
data-input-position="bottom"
data-theme="{% raw(theme=light) %}"
data-lang="{% raw(lang=en) %}"
data-loading="lazy"
data-loading="{% raw(loading=lazy) %}"
crossorigin="anonymous"
async
></script>
2 changes: 1 addition & 1 deletion templates/stackblitz.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<iframe
loading="lazy"
name="stackblitz"
loading="{% raw(loading=lazy) %}"
src="https://stackblitz.com/edit/{% raw(id) %}?embed=1&theme={% raw(theme=dark) %}&view=preview"
style="width: 100%; height: 100%; border: none; aspect-ratio: 16/9; border-radius: 1rem; background: black"
></iframe>
2 changes: 1 addition & 1 deletion templates/youtube.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<iframe
allowfullscreen
loading="lazy"
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"
Expand Down

0 comments on commit e43c3fc

Please sign in to comment.