Open goblinfactory opened 5 months ago
I've just read through the code a bit and just probed around a little.
I think, this here is the part where the variables (in data
) get populated, but maybe I'm wrong:
https://github.com/nuejs/nue/blob/043ce76236e2e3365f4d7893ba956e2affba6161/packages/nuekit/src/nuekit.js#L73
Interesting variables:
page
: json of md page content (probably result of https://github.com/nuejs/nue/blob/043ce76236e2e3365f4d7893ba956e2affba6161/packages/nuemark/src/parse.js#L8)header
, content
, footer
: generated html for part … of pageI'm not sure, if this helps at all, but maybe you can do something with page.*
Helpful simple code snippet to show variables (in this case page
)
<!-- layout.html -->
<main>
<pre><code>{ JSON.stringify(page, null, 2) }</code></pre>
<slot for="content" />
</main>
Edit: found this doc section: https://nuejs.org/docs/reference/nuemark-api.html#page
Add default
text
property to defaultdata
object available to page layoutsBackground;
I was modifying my blog ; blog.alanhemmings.com that uses Nuejs, and I was fixing some rough edges that was stopping Linkedin previews from working when pasting a blog url.
In order to pass the linkedin post checker "checks" (https://www.linkedin.com/post-inspector/) I needed to make a few changes to my
/posts/layout.html
template to support the required meta tags that Linkedin looks for.I was cheating and using the title as the title as well as the description ` but Linkedin gave me a warning saying that the description needs to be a minimum of 100 characters
At first I tried
content="{ text.substring(0,100) }"
and that didnt work. I triedcontent="{ content.textContent.substring(0,100) }"
thinking that content was perhaps a dom element. I also tried parsing the content as Dom and then reading textContent but that didnt work either.I also tried reading the nuekit src, focusing on the code for
pushMeta
but couldn't see any way to access the textContent property of content.In the end I just added
summary
field to the markdownfront matter
, and usedcontent="{ summary }"
and manually added in a 100 character summary.However, that's extra hoops I have to jump through and can easily result in the summary not matching the actual content.
More importantly it interferes with the flow of writing content having to worry about and remember that when i'm writing for Linkedin I need another
front matter
variable, when other times I do not. That feels like programming and not writing! So breaks the "flow" of writing. (it also feels like this breaks the separations of concerns that Nuejs praises as a core value, essentially repeatingfront matter
configuration data because of how the page will be consumed.)What I'd prefer to have is access to the text property of the content as a field called
text
and then simply do this;That will allow me to override it automatically picking the first 100 text characters by providing a summary in my
front matter
.{summary}
metadata to blog post (front matter
)Note: there are more tags that are required for Linked in addition to the
{summary}
, I'll write a short blog post on what was finally needed. The point is that I was able to update mylayout.html
to handle everything automatically except for the summary, hence this new issue request.