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

Allow custom HTML in <head>. #385

Merged
merged 8 commits into from
Sep 13, 2020
Merged

Allow custom HTML in <head>. #385

merged 8 commits into from
Sep 13, 2020

Conversation

vizziv
Copy link
Contributor

@vizziv vizziv commented Sep 11, 2020

Adds headHtml : Optional Text option to the configuration. It can be set in one of two ways, but not both simultaneously.

  • The option can be set as usual in ./neuron.dhall.
  • If the file ./head.html exists, then headHtml is set to Some [head.html's contents].

Addresses #362 directly. Also solves or enables workarounds for several other issues (e.g. #212, #361, #383).

Adds `headHtml : Optional Text` option to the configuration.
It can be set in one of two ways, but not both simultaneously.

- The option can be set as usual in `./neuron.dhall`.
- If the file `./head.html` exists, then `headHtml` is set to its
`Some [head.html's contents]`.
@srid
Copy link
Owner

srid commented Sep 11, 2020

@vizziv Thanks! Taking a quick look at the diff, I see that this differs from #362 in two ways:

  • Why the neuron.dhall configuration, over just using head.html if it exists (see convention over configuration)?
  • Why is the default mathjax script still included? I thought we would have a default snippet for head.html when it is not specified by the user, and that this snippet would contain the existing mathjax include. The idea being that if the user overrides head.html, they become responsible for including whatever math script (math or katex or whatever) they need.

@vizziv
Copy link
Contributor Author

vizziv commented Sep 11, 2020

The answer in both cases is that I chose a solution that made the fewest changes to the code, as I wanted to submit the minimally invasive patch that added the feature. But I'm happy to make both changes.

Regarding how to organize the code for the first change: should we use the Config type to store head.html's contents, or should we create a new module and type to handle it? (Or should we just put the code reading head.html directly into Main?)

@vizziv
Copy link
Contributor Author

vizziv commented Sep 11, 2020

Another question about the second change: right now we replace $/$ pairs with \(/\) pairs for MathJax's sake. Should disabling MathJax entail disabling this replacement?

@srid
Copy link
Owner

srid commented Sep 11, 2020

Checkout how the icon and manifest files are handled for inspiration. They are loaded in src/app/Main.hs as manifest and passed around (along with config) as a function argument to renderRoutePage. You can do the same for head.html. And notice how Neuron.Web.Manifest handles the creation of the manifest type, including handing the default case - of using neuron logo as the favicon.

@srid
Copy link
Owner

srid commented Sep 11, 2020

re: MathJax - I'm not sure what you mean; neuron doesn't do any special processing, aside from letting commonmark handle it (see CE.mathSpec in Neuron.Reader.Markdown). The mathJaxSupport config field should be ... made to be totally ignored in this PR (with a deprecation warning), and entirely removed one day, I think.

@srid
Copy link
Owner

srid commented Sep 11, 2020

You can probably sneak in the head.html stuff in a new field of the Neuron.Web.Manifest:Manifest type, while renaming that module/type suitably (it won't just be a "manifest" anymore).

@vizziv
Copy link
Contributor Author

vizziv commented Sep 11, 2020

Ahh, I'd already made a new module for this, creatively named HeadHtml. But it could definitely be easily combined with (an appropriately renamed) Manifest either now or in the future.

@vizziv
Copy link
Contributor Author

vizziv commented Sep 11, 2020

The mathJaxSupport config field should be ... made to be totally ignored in this PR (with a deprecation warning), and entirely removed one day, I think.

I've removed mathJaxSupport from Config. I wasn't sure how to best add a deprecation warning, so instead we throw an error. This also throws an error for other spurious fields in neuron.dhall.

I'm not sure how you want to update the guide to reflect these changes, so I'll leave that to you and others if that's okay.

re: MathJax - I'm not sure what you mean; neuron doesn't do any special processing, aside from letting commonmark handle it (see CE.mathSpec in Neuron.Reader.Markdown).

Yeah, looks like the $/$-to-\(/\) conversion is determined by some combination of commonmark-pandoc and pandoc. Will table this for now.

neuron/src/app/Main.hs Outdated Show resolved Hide resolved
neuron/src/app/Main.hs Outdated Show resolved Hide resolved
neuron/src/app/Neuron/Config.hs Outdated Show resolved Hide resolved
neuron/src/app/Neuron/Config.hs Outdated Show resolved Hide resolved
neuron/src/app/Neuron/Web/View.hs Outdated Show resolved Hide resolved
neuron/src/app/Neuron/Web/View.hs Outdated Show resolved Hide resolved
neuron/src/lib/Neuron/Config/Type.hs Outdated Show resolved Hide resolved
@srid
Copy link
Owner

srid commented Sep 11, 2020

About the deprecation warning .. okay, let's not worry about it; let's ignore the mathjax field silently if used by the user. I added some comments in your PR.

About the $ -> ( conversion, that happens here: https://github.com/srid/reflex-dom-pandoc/blob/259c7a881dd4ba69f82ac2fdec83ddf8f5ee0fc5/src/Reflex/Dom/Pandoc/Document.hs#L204

@vizziv vizziv requested a review from srid September 12, 2020 05:27
Copy link
Owner

@srid srid left a comment

Choose a reason for hiding this comment

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

@vizziv You know what, I'm now not sure if it is so important to support backwards compact, especially if it makes config parsing rather complex.

Most users I imagine won't have mathJaxSupport = false in their config. Those that do, can always remove it when next updating neuron.

So let's get rid of the config fields check entirely. Please undo the Config changes in your PR, except for removing mathJaxSupport field entirely from the Config type.

neuron/src/app/Neuron/Config.hs Outdated Show resolved Hide resolved
neuron/src/app/Neuron/Web/View.hs Outdated Show resolved Hide resolved
@vizziv
Copy link
Contributor Author

vizziv commented Sep 13, 2020

Okay, I undid the config changes (except I removed the mathJaxSupport field) and explained DOCTYPE.

The Neuron.Config and Neuron.Config.Type commit histories on this branch are now kind of messy, so squashing these commits upon merging makes sense.

@srid srid changed the base branch from master to dev September 13, 2020 19:34
@srid srid merged commit 8d61054 into srid:dev Sep 13, 2020
@vizziv vizziv deleted the custom-head branch September 13, 2020 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants