Skip to content

Commit

Permalink
docs: update gisucus and usage docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Addict committed Feb 12, 2024
1 parent 9c7fd78 commit 4e08b2f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions example/src/third-party/giscus.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@ giscus.theme = "light"
giscus.lang = "en"
```

## Good to know
## Refuse to Connect

Giscus is only supported while your app is deployed. You can't see it if you open it with **file://** protocol which is mdbook default behavior.
Giscus will refuse to connect if you build and preview your book with **file://** protocol. The easiest solution is to use some static server so that you can preview your book with **http://** protocol.

The simple way is to serve your book with a static server so that you can see the giscus by opening it with **http://** protocol. Typically, there is no problem if you deploy your book to GitHub Pages or Netlify. But if you want to see it locally, you can use below commands to serve your book.
For exampe:

**node.js installed**

```sh
npx serve book
```

Which will serve your book at [http://localhost:3000](http://localhost:3000).

**python installed**

```sh
python -m http.server --directory book
```

Which will serve your book at [http://localhost:8080](http://localhost:8080).
2 changes: 2 additions & 0 deletions example/src/usage.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Usage

## Installation

There are two ways to install this plugin.
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn parse_options(options_str: &str) -> Vec<(String, String)> {
let options_str = format!("<p {}/>", options_str);
// parse the options and warn if there is an syntax error
let doc = roxmltree::Document::parse(&options_str)
.expect("Failed to parse options, please check your syntax");
.expect("Failed to parse embed options, please check your syntax");
let mut options = Vec::new();
for attr in doc.root_element().attributes() {
options.push((attr.name().to_owned(), attr.value().to_owned()));
Expand Down
9 changes: 5 additions & 4 deletions templates/announcement-banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.announcement-banner {
color: black;
z-index: 150;
display: flex;
position: relative;
flex-direction: column;
justify-content: center;
Expand Down Expand Up @@ -67,7 +66,7 @@
}
</style>

<div class="announcement-banner" data-theme="{% theme|default %}" data-id="{% id %}">
<div style="display: none" class="announcement-banner" data-theme="{% theme|default %}" data-id="{% id %}">
{% markdown(message) %}
<button type="button">X</button>
</div>
Expand All @@ -78,8 +77,10 @@
const message = banner.querySelector("p").textContent;
const localData = JSON.parse(localStorage.getItem("mdbook-announcement-banner"));

if (localData && localData.hide === true && localData.id === id) banner.remove();
else {
if (!localData || localData.id !== id || localData.hide !== true) {
// update banner display style to be flex
banner.style.display = "flex";

// move banner before page class element slibling
const page = document.querySelector(".page");
page.parentNode.insertBefore(banner, page);
Expand Down

0 comments on commit 4e08b2f

Please sign in to comment.