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 JSON-LD plugin #453

Open
oscarotero opened this issue Jul 27, 2023 · 3 comments · Fixed by #687
Open

Add JSON-LD plugin #453

oscarotero opened this issue Jul 27, 2023 · 3 comments · Fixed by #687
Labels
enhancement New feature or request

Comments

@oscarotero
Copy link
Member

oscarotero commented Jul 27, 2023

Enter your suggestions in details:

More info: https://jsonld.com/
It could use: https://www.npmjs.com/package/schema-dts
Inspo: https://github.com/codiume/orbit/tree/main/packages/astro-seo-schema

@oscarotero oscarotero added the enhancement New feature or request label Jul 27, 2023
@oscarotero oscarotero changed the title Add LD to metas plugin Add LD plugin Oct 10, 2023
@oscarotero oscarotero changed the title Add LD plugin Add JSON-LD plugin Oct 10, 2023
@shuaixr
Copy link

shuaixr commented Nov 5, 2024

Hi, can I do this? I think the best way is to modify the metas plugin, what do you think?

@oscarotero
Copy link
Member Author

oscarotero commented Nov 6, 2024

Hey @shuaixr
Sure, thanks for your help!!

I don't think we should include this in the metas plugin, because JSON-LD is too big and complex.
Take a look to astro-seo-schema and astro-seo-meta, they are different packages and I think Lume plugins should separate them too.

JSON-LD is hard, so I'd like a plugin that help to create entities easily. Maybe using a library like https://www.npmjs.com/package/schema-dts could be nice because it provides types to autocomplete the values. But would like to investigate if we can do it even easier. Let's see this example:

{
  '@type': 'Person',
  '@id': 'https://my.site/#alyssa',
  name: 'Alyssa P. Hacker',
  hasOccupation: {
    '@type': 'Occupation',
    name: 'LISP Hacker',
    qualifications: 'Knows LISP',
  },
  mainEntityOfPage: {'@id': 'https://my.site/about/#page'},
  subjectOf: {'@id': 'https://my.site/about/#page'},
},

It should handle the URLs of the pages. The URLs https://my.site/#alyssa and https://my.site/about/#page should be managed by Lume, so if the site is built with a different url (deno task build --location https://other.site) all these URLs should change. I imagine a script that search recursively by all @id and url keys that doesn't contain the domain and complete them. For example:

{
  '@type': 'Person',
  '@id': '#alyssa',
  name: 'Alyssa P. Hacker',
  hasOccupation: {
    '@type': 'Occupation',
    name: 'LISP Hacker',
    qualifications: 'Knows LISP',
  },
  mainEntityOfPage: {'@id': '/about/#page'},
  subjectOf: {'@id': '/about/#page'},
},

It must allow aliases, in the same way as metas. For example:

{
  '@type': 'Person',
  '@id': '#alyssa',
  name: '=user.name',
  hasOccupation: {
    '@type': 'Occupation',
    name: '=user.occupation.name',
    qualifications: '=user.occupation.qualifications',
  },
  mainEntityOfPage: {'@id': '/about/#page'},
  subjectOf: {'@id': '/about/#page'},
},

It should be able to show or hide entities if some values are empty. For example, if the user doesn't have occupation, instead of output the properties with empty values:

{
  '@type': 'Person',
  '@id': 'https://my.site/#alyssa',
  name: 'Alyssa P. Hacker',
  hasOccupation: {
    '@type': 'Occupation',
    name: '',
    qualifications: '',
  },
  mainEntityOfPage: {'@id': 'https://my.site/about/#page'},
  subjectOf: {'@id': 'https://my.site/about/#page'},
},

It should omit this object:

{
  '@type': 'Person',
  '@id': 'https://my.site/#alyssa',
  name: 'Alyssa P. Hacker',
  mainEntityOfPage: {'@id': 'https://my.site/about/#page'},
  subjectOf: {'@id': 'https://my.site/about/#page'},
},

It would be nice if the plugin checked the data structure, in order to detect missing properties, or not found relations between entities.

What do you think? I know it's complex, so we can start with the basics and improve it little by little.

@shuaixr
Copy link

shuaixr commented Nov 7, 2024

After closer look at the metas plugin, I think you're right. I'll open a draft pr soon

@shuaixr shuaixr mentioned this issue Nov 7, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants