Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axomdbook #339

Merged
merged 4 commits into from
May 30, 2023
Merged

axomdbook #339

merged 4 commits into from
May 30, 2023

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented May 23, 2023

This adds ./oranda-css/mdbook-theme/ which is vendored into the oranda binary
at build time. If mdbook.theme = true is set (the default, you need to opt out),
we will override your mdbook theme with our own, adding "axo" and "axo-light"
themes which match the default oranda light/dark themes.

The existing builtin mdbook themes should remain and behave the same, and can
still be selected.

We do not modify the source of your mdbook -- we generate a new temp theme dir
in oranda's output dir (./public/) and tell mdbook to use that as the theme.
These themes are currently hardcoded, but use the same css-variable machinery
that mdbook is built around. As such they are primarily defined by a set of
values in variables.css that can easily be updated in the future.

Note that as a result of this, running 'mdbook build' on its own will now
produce different results from having oranda run it. In the future we will
probably expose a "vendor" option that modifies your tree so that vanilla
mdbook theme runs produce the same results (that was actually the original
implementation, but we felt this was less intrusive/surprising as a default).

Some changes made to the default mdbook theme files:

  • To avoid issues with running other mdbook instances (or toggling this on/off),
    we change the default "mdbook-theme" localStorage key to "axomdbook-theme".
    This prevents vanilla instances of mdbook from seeing that you have selected
    "axo" as a theme, which would otherwise cause those instances to crash due to
    a failed lookup of that name.

  • A new highlightjs stylesheet, axoHighlight, has been added to book.js and
    index.hbs. Because mdbook doesn't really support adding extra stylesheets
    (only overloading the "main" one, which would clash with the default mdbook
    themes), we inject this stylesheet by just copying it into the final mdbook
    output after mdbook has run. axoHighlight is currently base16/material.css,
    which is stored in-tree as
    oranda-css/mdbook-theme/highlight-js-themes/base16-material.css. It is
    selected using your oranda syntax highlighting theme, but that feature was
    already limited to one value.

  • To avoid issues with adding new highlightjs stylesheets, we now disable all
    of them in a loop whenever a theme is selected, so each case only needs to be
    responsible for enabling itself, and doesn't need to enumerate all the other
    ones that need to be disabled.

  • A few edits were made to the css to add more distinctions-via-variables,
    like allowing "main titles" to be styled differently from other headings,
    and allowing themes to select the font.

  • axo/axo-light are hardcoded in the css to disable padding/bg-color-changes
    to inline code snippets, as this is the style we use in oranda. I couldn't
    find a way to make this controlled by variables, as this is specifically
    shadowing values set by the currently enabled highlightjs stylesheet, and
    there's no way to "disable" a css rule with just variables (that I know).

  • fonts.css was changed to import axo's preferred fonts instead of the
    builtin ones. I'm a bit fuzzy on whether the vendored fonts are unvendored
    by this, because this behaviour was recently being changed in mdbook.

@Gankra
Copy link
Contributor Author

Gankra commented May 23, 2023

alright, did a bunch of work on this and it's looking a lot better.

Some issues:

  • standard mdbook themes don't have their fonts vendored anymore so they get console errors (left a FIXME in fonts.css)
  • standard mdbook themes lose the bg/padding around inline code (left a FIXME in variables.css)
  • our quote blocks don't really match anything (oranda and blog.axo.dev completely disagree on the style)

src/site/mdbook.rs Outdated Show resolved Hide resolved
src/site/mdbook.rs Outdated Show resolved Hide resolved
@Gankra
Copy link
Contributor Author

Gankra commented May 26, 2023

wait what

@Gankra Gankra reopened this May 26, 2023
Copy link
Contributor

@shadows-withal shadows-withal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, i think this can be merged after reverting the web.yml change and squashing

Gankra added 3 commits May 30, 2023 11:31
This adds oranda-css/mdbook-theme which is vendored into the oranda binary
at build time. If mdbook.theme = true is set (the default, you need to opt out),
we will override your mdbook theme with our own, adding "axo" and "axo-light"
themes which match the default oranda light/dark themes.

The existing builtin mdbook themes should remain and behave the same, and can
still be selected.

We do not modify the source of your mdbook -- we generate a new temp theme dir
in oranda's output dir (./public/) and tell mdbook to use that as the theme.
These themes are currently hardcoded, but use the same css-variable machinery
that mdbook is built around. As such they are primarily defined by a set of
values in variables.css that can easily be updated in the future.

Note that as a result of this, running 'mdbook build' on its own will now
produce different results from having oranda run it. In the future we will
probably expose a "vendor" option that modifies your tree so that vanilla
mdbook theme runs produce the same results (that was actually the original
implementation, but we felt this was less intrusive/surprising as a default).

Some changes made to the default mdbook theme files:

* To avoid issues with running other mdbook instances (or toggling this on/off),
we change the default "mdbook-theme" localStorage key to "axomdbook-theme".
This prevents vanilla instances of mdbook from seeing that you have selected
"axo" as a theme, which would otherwise cause those instances to crash due to
a failed lookup of that name.

* A new highlightjs stylesheet, axoHighlight, has been added to book.js and
index.hbs. Because mdbook doesn't really support adding extra stylesheets
(only overloading the "main" one, which would clash with the default mdbook
themes), we inject this stylesheet by just copying it into the final mdbook
output after mdbook has run. axoHighlight is currently base16/material.css,
which is stored in-tree as
`oranda-css/mdbook-theme/highlight-js-themes/base16-material.css`. It is
selected using your oranda syntax highlighting theme, but that feature was
already limited to one value.

* To avoid issues with adding new highlightjs stylesheets, we now disable all
of them in a loop whenever a theme is selected, so each case only needs to be
responsible for enabling itself, and doesn't need to enumerate all the other
ones that need to be disabled.

* A few edits were made to the css to add more distinctions-via-variables,
like allowing "main titles" to be styled differently from other headings,
and allowing themes to select the font.

* axo/axo-light are hardcoded in the css to disable padding/bg-color-changes
to inline code snippets, as this is the style we use in oranda. I couldn't
find a way to make this controlled by variables, as this is specifically
shadowing values set by the currently enabled highlightjs stylesheet, and
there's no way to "disable" a css rule with just variables (that I know).

* fonts.css was changed to import axo's preferred fonts instead of the
builtin ones. I'm a bit fuzzy on whether the vendored fonts are unvendored
by this, because this behaviour was recently being changed in mdbook.
@Gankra Gankra merged commit 54c94c8 into axodotdev:main May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants