How to add meta tag to mdBook?

235 Views Asked by At

I'd like to add Twitter Card via meta tag to mdBook.

How can I add meta tags (example below) to mdBook?

<meta name="twitter:card" content="summary"></meta>

Current workaround is to execute sed command after mdbook build.

2

There are 2 best solutions below

0
ynn On BEST ANSWER

You can use the theme feature of mdBook.

  1. Create a random mdBook with --theme option.

    $ mdbook init --theme abc
    
  2. Confirm theme/ directory is created.

    $ ls
    
    book  book.toml  src  theme
    
  3. Copy theme/ directory to your mdBook directory.

  4. Edit theme/index.hbs.

  5. Execute mdbook build as usual.

0
user13840624 On

As noted in https://rust-lang.github.io/mdBook/format/theme/index.html, you can specify a custom head.hbs file (which you can put into theme/) and add custom <head> tags to it.