Page 1 of 1

Wie konfigurieren Sie benutzerdefinierte Schriftarten in MDBook, die automatisch im generierten Buch verwendet werden?

Posted: 13 Apr 2025, 07:47
by Anonymous
Vor ein paar Tagen habe ich MDBook gefunden. Ich bin aufgeregt, mich nach einem einfachen, kleinen, nicht
oveloded statischen Site -Generator zu betrachten. Es ist einfach zu bedienen, einfach,
schnell und komplett gut gestaltet. Ich hätte gerne
die Schriftart in einem angepassten Thema anpassen. Oben "Standard-Themen" ist definiert als die Themenfarbe
standardmäßig in der Dropdown "Änderungsthema ändern". < /p>
Wie passt das zusammen? In meiner Konfiguration funktioniert das automatische Kopieren von Schriftartdateien
nicht. Ich habe ein kleines Bash -Skript geschrieben, das das Kopieren nach dem Erstellen von Buchausgaben durchführt.

Code: Select all

mdbook init testBook --theme
[*]rename the 'theme' directory to 'peters-theme'

[*]create new directory 'peters-theme/fonts

  • copy the Libertinus TeX Schreiben Sie in dieses Verzeichnis
  • Erstellen Sie eine neue CSS-Datei 'Peters-theMe/Schriftarten/libertinus-sans-font.css'

    Code: Select all

    @font-face {
    font-family: libertinus-sans;
    font-style: normal;
    font-weight: normal;
    src: url('LibertinusSans-Regular.otf') format('opentype');
    }
    
    @font-face {
    font-family: libertinus-sans;
    font-style: italic;
    font-weight: normal;
    src: url('LibertinusSans-Italic.otf') format('opentype');
    }
    
    @font-face {
    font-family: libertinus-sans;
    font-style: normal;
    font-weight: bold;
    src: url('LibertinusSans-Bold.otf') format('opentype');
    }
    < /code>
    < /li>
    < /ul>
    [list]
     Tweak-Datei 'Peters-theMe /CSS /General.css' < /li>
    < /ol>
    
      < /P>
      add zusätzliche css [url=viewtopic.php?t=18708]importieren[/url] < /p> < /P.@import '../fonts/libertinus-sans-font.css'; /* added individually: use 'libertinus sans' fonts */
    < /code>
    < /li>
      HTML -Selektor ändern < /p>
    html {
    font-family: libertinus-sans; /* added individually: use 'libertinus sans' fonts */
    color: var(--fg);
    background-color: var(--bg);
    text-size-adjust: none;
    }
    
[*] Datei erstellen 'Peters-theMe/Fonts/libertinus-sans-font.css'

Code: Select all

@font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: normal;
src: url('LibertinusSans-Regular.otf') format('opentype');
}

@font-face {
font-family: libertinus-sans;
font-style: italic;
font-weight: normal;
src: url('LibertinusSans-Italic.otf') format('opentype');
}

@font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: bold;
src: url('LibertinusSans-Bold.otf') format('opentype');
}
[*] Schriftdateien in 'peters-themen/fonts' verzeichnis

[/list]

[*]'peters-theme/fonts/libertinsanssb. />'peters-theme/fonts/libertinussans-italic.otf'
[*]'peters-theme/fonts/libertinussans-reegular 'peters-theme/index.hbs'

Code: Select all


{{#if copy_fonts}}


{{/if}}
< /code>
< /li>
  BASH-Skript 'Build-book.sh' (mit Kopieren als Problemumgehung) < /p>
#!/bin/bash
#
# Author: Peter
# Date: 2020-11-20
#
ROOTFOLDER='/home/peter/Documents/Peter/Notes/mdBook/testBook/'
#
# change to book directory
cd $ROOTFOLDER
#
# clean up old book files
mdbook clean
#
# build the book
mdbook build
#
# copy fonts for custom theme
cp -r ./peters-theme/fonts/ ./book/
#
# display book in browser
mdbook serve --open

Grüße
Peter