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

Add defaulttext property to default data object available to page layouts. #269

Open
goblinfactory opened this issue Apr 28, 2024 · 1 comment
Labels
improvement question Further information is requested

Comments

@goblinfactory
Copy link
Contributor

goblinfactory commented Apr 28, 2024

Add defaulttext property to default data object available to page layouts

Background;

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

 <meta prefix="og: http://ogp.me/ns#" property="og:description" content="{ title }">

At first I tried content="{ text.substring(0,100) }" and that didnt work. I tried content="{ 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 markdown front matter, and used content="{ 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 repeating front 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;

    <meta prefix="og: http://ogp.me/ns#" property="og:description" content="{ summary ?? text.subtring(0,100) }">

That will allow me to override it automatically picking the first 100 text characters by providing a summary in my front matter.

Priority Value Rational Workaround
Low (there is a simple workaround) Medium to high (This should be a small piece of low risk medium to high value work that can be added to almost any future release.) Also, it helps users promote their Nuejs blog using linkedIn, and other platforms that rely on open graph metadata. Manually add {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 my layout.html to handle everything automatically except for the summary, hence this new issue request.

@nobkd nobkd added question Further information is requested improvement labels Apr 28, 2024
@nobkd
Copy link
Collaborator

nobkd commented Jul 26, 2024

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:

async function getPageData(path) {


Interesting variables:

  • page: json of md page content (probably result of
    export function parsePage(lines) {
    )
  • header, content, footer: generated html for part … of page
  • variables from frontmatter / site.yaml / ...?
  • collection(s)

I'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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants