Skip to content

Commit

Permalink
feat: add support for lambdalisue/rs-mdbook-alerts (#135)
Browse files Browse the repository at this point in the history
Co-authored-by: sgoudham <sgoudham@gmail.com>
  • Loading branch information
uncenter and sgoudham authored Nov 15, 2024
1 parent 0d591aa commit cd3ca47
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 65 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v2
with:
mdbook-version: "0.4.40"
mdbook-version: "0.4.42"
- name: Download mdbook-admonish
run: |
mkdir ${{ env.TARGET }}
Expand All @@ -29,6 +29,14 @@ jobs:
env:
VERSION: "v1.18.0"
TARGET: "mdbook-admonish-v1.18.0-x86_64-unknown-linux-gnu"
- name: Download mdbook-alerts
run: |
mkdir ${{ env.TARGET }}
curl -sSL https://github.com/lambdalisue/rs-mdbook-alerts/releases/download/${{ env.VERSION }}/${{ env.TARGET }}.tar.gz | tar -xz --directory=${{ env.TARGET }}
echo `pwd`/${{ env.TARGET }} >> $GITHUB_PATH
env:
VERSION: "v0.6.9"
TARGET: "mdbook-alerts-x86_64-unknown-linux-gnu"
- name: Setup PNPM
uses: pnpm/action-setup@v3
- name: Setup Node
Expand Down
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@
rm -d fonts css
```

3. Download the CSS files from the [latest GitHub release](https://github.com/catppuccin/mdBook/releases/latest) to the `theme` directory:

- [catppuccin.css](https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin.css)
- [catppuccin-admonish.css](https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin-admonish.css)
(**Only required if you are using
[mdbook-admonish](https://github.com/tommilligan/mdbook-admonish)**)
3. Download the [catppuccin.css](https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin.css)
file from the [latest GitHub release](https://github.com/catppuccin/mdBook/releases/latest) to the `theme`
directory.

See the [Supported Plugins](#supported-plugins) section below for integrations with other
mdBook plugins.

4. Update `additional-css` key within the `book.toml` as shown below

```diff
[output.html]
-additional-css = []
+additional-css = ["./theme/catppuccin.css", "./theme/catppuccin-admonish.css"]
+additional-css = ["./theme/catppuccin.css"]
```

5. Edit the `index.hbs` file to include the Catppuccin flavours:
Expand Down Expand Up @@ -103,7 +103,20 @@
+ preferred-dark-theme = "mocha"
```

6. Build using `mdbook build` and enjoy your new catppuccin flavours!
6. Build using `mdbook build` and enjoy your new Catppuccin flavours!

### Supported Plugins

This theme also generates CSS files to style elements added by other mdBook
plugins. We support the following list of plugins:

| Plugin | CSS File |
| ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| [mdbook-admonish](https://github.com/tommilligan/mdbook-admonish) | [catppuccin-admonish.css](https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin-admonish.css) |
| [mdbook-alerts](https://github.com/lambdalisue/rs-mdbook-alerts) | [catppuccin-alerts.css](https://github.com/catppuccin/mdBook/releases/latest/download/catppuccin-alerts.css) |

The CSS file(s) can be downloaded and added to the `additional-css` key shown
in step `4.` of the [Usage](#usage) section.

## Development

Expand All @@ -118,25 +131,10 @@

```shell
cd palette
npm install
npm run build
pnpm install
pnpm run build
```

## 🙋 FAQ

- Q: **_"What's the `catppuccin-admonish.css` file?"_**\
A: It is a CSS file that is used to style the admonishments that are generated
by [mdbook-admonish](https://github.com/tommilligan/mdbook-admonish).
**You can remove this file if you are not using this plugin.**

E.g.

```diff
[output.html]
- additional-css = ["./theme/catppuccin.css", "./theme/catppuccin-admonish.css"]
+ additional-css = ["./theme/catppuccin.css"]
```

## Acknowledgement

[mdbook-admonish](https://github.com/tommilligan/mdbook-admonish) for
Expand Down
3 changes: 3 additions & 0 deletions example/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ title = "Catppuccin's mdBook"
command = "mdbook-admonish"
assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`

[preprocessor.alerts]

[output.html]
default-theme = "mocha"
preferred-dark-theme = "mocha"
additional-css = [
"./theme/catppuccin.css",
"./theme/catppuccin-admonish.css",
"./theme/mdbook-admonish.css",
"./theme/catppuccin-alerts.css",
]
no-section-label = true
git-repository-url = "https://github.com/catppuccin/mdBook"
Expand Down
1 change: 1 addition & 0 deletions example/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

- [Landing](./landing.md)
- [Admonishments](./admonish.md)
- [Alerts](./alerts.md)
- [Super Secret](./secret.md)
24 changes: 24 additions & 0 deletions example/src/alerts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Reference

The following alerts are implemented by the
[mdbook-alerts](https://github.com/lambdalisue/rs-mdbook-alerts) plugin and are
automatically themed to match Catppuccin.

## Alerts

All supported alerts are listed below.

> [!NOTE]
> Highlights information that users should take into account, even when skimming.
> [!TIP]
> Optional information to help a user be more successful.
> [!IMPORTANT]
> Crucial information necessary for users to succeed.
> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.
> [!CAUTION]
> Negative potential consequences of an action.
1 change: 1 addition & 0 deletions example/theme/catppuccin-alerts.css
53 changes: 16 additions & 37 deletions example/theme/index.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE HTML>
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
<html lang="{{ language }}" class="{{ default_theme }} sidebar-visible" dir="{{ text_direction }}">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
Expand Down Expand Up @@ -52,15 +52,17 @@
<!-- MathJax -->
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
{{/if}}
</head>
<body class="sidebar-visible no-js">
<div id="body-container">

<!-- Provide site root to javascript -->
<script>
var path_to_root = "{{ path_to_root }}";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
</script>

<!-- Start loading toc.js asap -->
<script src="{{ path_to_root }}toc.js"></script>
</head>
<body>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
Expand All @@ -82,19 +84,16 @@
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var html = document.querySelector('html');
const html = document.documentElement;
html.classList.remove('{{ default_theme }}')
html.classList.add(theme);
var body = document.querySelector('body');
body.classList.remove('no-js')
body.classList.add('js');
html.classList.add("js");
</script>

<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">

<!-- Hide / unhide sidebar before it is displayed -->
<script>
var body = document.querySelector('body');
var sidebar = null;
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
Expand All @@ -104,41 +103,21 @@
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
body.classList.remove('sidebar-visible');
body.classList.add("sidebar-" + sidebar);
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>

<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
{{#toc}}{{/toc}}
</div>
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>

<!-- Track and set sidebar scroll position -->
<script>
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
sidebarScrollbox.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
sidebarScrollbox.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
</script>

<div id="page-wrapper" class="page-wrapper">

<div class="page">
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Soothing pastel theme for mdBook",
"private": true,
"scripts": {
"build": "sass -I node_modules --no-charset --no-source-map src/catppuccin.scss:dist/catppuccin.css src/catppuccin-admonish.scss:dist/catppuccin-admonish.css"
"build": "sass -I node_modules --no-charset --no-source-map src/catppuccin.scss:dist/catppuccin.css src/catppuccin-admonish.scss:dist/catppuccin-admonish.css src/catppuccin-alerts.scss:dist/catppuccin-alerts.css"
},
"repository": {
"type": "git",
Expand All @@ -22,4 +22,4 @@
"sass": "^1.79.3"
},
"packageManager": "pnpm@9.12.3"
}
}
21 changes: 21 additions & 0 deletions src/catppuccin-alerts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@use "@catppuccin/palette/scss/catppuccin" as catppuccin;

@each $flavour, $color in catppuccin.$palette {
.#{$flavour} {
.mdbook-alerts-note {
--mdbook-alerts-color: #{map-get($color, "blue")};
}
.mdbook-alerts-tip {
--mdbook-alerts-color: #{map-get($color, "green")};
}
.mdbook-alerts-important {
--mdbook-alerts-color: #{map-get($color, "mauve")};
}
.mdbook-alerts-warning {
--mdbook-alerts-color: #{map-get($color, "yellow")};
}
.mdbook-alerts-caution {
--mdbook-alerts-color: #{map-get($color, "red")};
}
}
}

0 comments on commit cd3ca47

Please sign in to comment.