Search code examples
rustmarkdownmdbook

How to add meta tag to mdBook?


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.


Solution

  • 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.