-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Possibility of using custom templates #31
Comments
Interesting idea. I'd have to look carefully at the data provided to the template, since that would be a public supported API if people can write their own templates... |
Right now, the data passed to Jinja is an ad-hoc mixture of the JSON returned by GitHub, with some extra information thrown in, and re-organized into the hierarchy to display. Define DINGHY_SAVE_RESULT=1 in your environment, and run dinghy. It will write .json files alongside the .html files. You can get a sense of the data, and we can talk about approaches. |
The JSON data rendered by templates is mostly the GraphQL data returned by GitHub. But there is a bit of computed data added by dinghy, and some pieces have been re-parented to indicate hierarchy. All of the keys added by dinghy now have a `dinghy_` prefix for clarity. This is in support of issues #31 and #32.
I've just made a change on main to prefix all of the dinghy keys in the data to make it easier to distinguish between the data direct from GraphQL and the data computed or rearranged by dinghy: f9feac9. |
There's also the matter of the reverse-engineered <span class="label" style="--label-r:0;--label-g:82;--label-b:204;--label-h:215;--label-s:100;--label-l:40;">T: design</span> These are computed by a Python-provided function in the Jinja template, and rely on CSS copied from GitHub: .label {
padding: .2em .5em .1em .5em;
border-radius: 2em;
font-size: 75%;
opacity: .85;
vertical-align: middle;
white-space: nowrap;
/* GitHub label style computations, lifted from github.com */
border: 1px solid transparent;
--perceived-lightness: calc( ((var(--label-r) * 0.2126) + (var(--label-g) * 0.7152) + (var(--label-b) * 0.0722)) / 255 );
--lightness-switch: max(0, min(calc((var(--perceived-lightness) - var(--lightness-threshold)) * -1000), 1));
--lightness-threshold: 0.453;
--border-threshold: 0.96;
--border-alpha: max(0, min(calc((var(--perceived-lightness) - var(--border-threshold)) * 100), 1));
background: rgb(var(--label-r), var(--label-g), var(--label-b));
color: hsl(0, 0%, calc(var(--lightness-switch) * 100%));
border-color: hsla(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) - 25) * 1%), var(--border-alpha));
} Would you copy all of that into a custom template, or should it be provided somehow by dinghy? |
@thatlittleboy Another way to approach this: what would you like to change about the template? How would your custom template differ from mine? |
Thanks @nedbat , let me take some time to digest this information and get back to you over the weekend. Before looking through all these, my initial thoughts / idea with a custom template was to:
Obviously, some of these "options" could be baked into dinghy itself as CLI args/dinghy config, but for maximum flexibility, I thought a custom template was the easiest to achieve these. Then So this was just what I wanted to achieve with custom templates, I'll see if I can form more thoughts on how to practically achieve this, after I take a closer look at what you've written above! <3 |
For my personal use-case, I'm not intending to modify these in my templates. So ideally, it would be provided by dinghy. (But I'm also fine just copying it into my custom template if it comes down to that.) As for how this option can be realized: it would probably entail refactoring the css styles out into its own file (suppose <head>
...
<link rel="stylesheet" type="text/css" href="templates/css/base.css">
<link rel="stylesheet" type="text/css" href="templates/css/my-custom-css.css">
</head>
... (To be clear: So your default-provided template would just have Do you think this could work? |
I haven't done anything yet to help with the CSS, but in commit b4e750a, you can specify a |
Yep, I just copied I tested two changes with the template thus far:
https://github.com/thatlittleboy/github-digest/pull/2/files and result https://thatlittleboy.github.io/github-digest/ The handling/inheritance of CSS can be more ergonomic (as discussed above), but I'm satisfied with this solution for now. 😄 |
This is now released as part of dinghy 1.1.0. |
Is there a possibility of using custom Jinja templates when rendering the digest? Right now, it is always using the template bundled in with the project (
digest.html.j2
).Preferably the ability to customize different templates for different digests within the same
dinghy.yaml
.I imagine an API like
The text was updated successfully, but these errors were encountered: