Skip to content

Commit

Permalink
Footer with Vector Logo (#9)
Browse files Browse the repository at this point in the history
* bring in assets

* footer

* footer
  • Loading branch information
nerdai authored Feb 14, 2025
1 parent 22d74ba commit 3a7f07a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ chapter-level contributor sections featuring authors' GitHub profiles.
cargo install mdbook-ai-pocket-reference
```

1. Download the `src/bin/assets/mdbook-ai-pocket-reference.css` and add to your
book's root directory:

> [!NOTE]
> If working with `ai-pocket-reference` collection, then this additional css
> file is already included, and so this step can be safely skipped.
## Usage

1. Add to your `book.toml`:

```toml
[preprocessor.ai-pocket-reference]
command = "mdbook-ai-pocket-reference"

[output.html]
additional-css = ["mdbook-ai-pocket-reference.css"]
```

1. Add ai-pocket-reference header:
Expand Down Expand Up @@ -60,4 +70,3 @@ by Hu, Edward J. et...
Will render as:

<img width="846" alt="image" src="https://github.com/user-attachments/assets/a6812900-4f7f-4cc8-b0d4-1e4a67a558c0" />

7 changes: 6 additions & 1 deletion src/ai_pocket_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde_json::value::Map;
use std::collections::HashMap;

const AIPR_HEADER_TEMPLATE: &str = include_str!("./templates/header.hbs");
const AIPR_FOOTER_HTML: &str = include_str!("./templates/footer.html");
const WORDS_PER_MINUTE: usize = 200;

#[derive(Default)]
Expand Down Expand Up @@ -38,7 +39,11 @@ impl Preprocessor for AIPRPreprocessor {
book.for_each_mut(|section: &mut BookItem| {
if let BookItem::Chapter(ref mut ch) = *section {
let word_count = words_count::count(&ch.content);
let content = replace_all(&ch.content, word_count.words);
let mut content = replace_all(&ch.content, word_count.words);

// add footer with logo
content.push_str(AIPR_FOOTER_HTML);

// mutate chapter content
ch.content = content;
}
Expand Down
21 changes: 21 additions & 0 deletions src/bin/asserts/mdbook-ai-pocket-reference.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.vector-logo img {
height: 50px;
width: auto;
display: block;
margin-left: auto;
}

/* Light theme */
.light .vector-logo .dark-logo,
.rust .vector-logo .dark-logo { display: none; }
.light .vector-logo .light-logo,
.rust .vector-logo .light-logo { display: block; }

/* Dark themes */
.coal .vector-logo .light-logo,
.navy .vector-logo .light-logo,
.ayu .vector-logo .light-logo { display: none; }

.coal .vector-logo .dark-logo,
.navy .vector-logo .dark-logo,
.ayu .vector-logo .dark-logo { display: block; }
8 changes: 8 additions & 0 deletions src/templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="vector-logo">
<a href="https://vectorinstitute.ai/">
<img src="https://d3ddy8balm3goa.cloudfront.net/vector-ai-pocket-refs/vector-logo-default.png" alt="" class="light-logo">
</a>
<a href="https://vectorinstitute.ai/">
<img src="https://d3ddy8balm3goa.cloudfront.net/vector-ai-pocket-refs/vector-logo-dark.png" alt="" class="dark-logo">
</a>
</div>
3 changes: 3 additions & 0 deletions test_book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ title = "github-authors"

[preprocessor.github-authors]
command = "cargo run --manifest-path=../Cargo.toml --locked"

[output.html]
additional-css = ["mdbook-ai-pocket-reference.css"]
21 changes: 21 additions & 0 deletions test_book/mdbook-ai-pocket-reference.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.vector-logo img {
height: 50px;
width: auto;
display: block;
margin-left: auto;
}

/* Light theme */
.light .vector-logo .dark-logo,
.rust .vector-logo .dark-logo { display: none; }
.light .vector-logo .light-logo,
.rust .vector-logo .light-logo { display: block; }

/* Dark themes */
.coal .vector-logo .light-logo,
.navy .vector-logo .light-logo,
.ayu .vector-logo .light-logo { display: none; }

.coal .vector-logo .dark-logo,
.navy .vector-logo .dark-logo,
.ayu .vector-logo .dark-logo { display: block; }
5 changes: 5 additions & 0 deletions tests/test_preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ fn aipr_header_works() {
);
assert!(!ch1.contains("blob/main/notebooks/"));
assert!(ch1.contains("<small>Reading time: "));
assert!(ch1.contains("<div class=\"vector-logo\">"));

// chapter 1.1
assert!(
ch1_1.contains("https://img.shields.io/badge/Suggest_an_Edit-black?logo=github&style=flat")
);
assert!(ch1_1.contains("blob/main/notebooks/nlp/attention.ipynb"));
assert!(ch1_1.contains("<small>Reading time: "));
assert!(ch1_1.contains("<div class=\"vector-logo\">"));

// chapter 1.2
assert!(
ch1_2.contains("https://img.shields.io/badge/Suggest_an_Edit-black?logo=github&style=flat")
);
assert!(!ch1_2.contains("blob/main/notebooks/"));
assert!(!ch1_2.contains("<small>Reading time: "));
assert!(ch1_2.contains("<div class=\"vector-logo\">"));
}

0 comments on commit 3a7f07a

Please sign in to comment.