We also need to make the getEntity function public, to allow sites that don’t use the normalized structure of Frontity to override it. We’re going to move it to libraries.source.getEntity as this is something related to source and other packages use it as well.
By the way, I’m going to try using a derived property instead of a library, I think it could have a better API, something like state.source.entity(link). It could be overwritten as well.
Oh, my mistake, we can’t use the same functions because we need the arg is Type syntax and the types are different.
function isTaxonomy(data: Data): data is TaxonomyData {
return (data as TaxonomyData).isTaxonomy === true;
}
function isTaxonomy(entity: Entity): entity is TaxonomyEntity {
return !!(entity as TaxonomyEntity).taxonomy;
}
Then maybe we need to distinguish between those with different entry points:
import { isPostType } from "@frontity/source/data";
const data = state.source.get(state.router.link);
if (isPostType(data)) {
//...
}
import { isPostType } from "@frontity/source/entity";
const entity = state.source.entity(state.router.link);
if (isPostType(entity)) {
//...
}
Or different namings:
import { isPostTypeData } from "@frontity/source";
const data = state.source.get(state.router.link);
if (isPostTypeData(data)) {
//...
}
import { isPostTypeEntity } from "@frontity/source";
const entity = state.source.entity(state.router.link);
if (isPostTypeEntity(entity)) {
//...
}
I implemented state.source.entity() this way because for me it wasn’t clear how to know the type of an entity depending on the given link but I didn’t realize it is the same case as state.source.data!
This means that if you are using Yoast ^14.0, you should use this new package . And, if you’re using a previous version where the REST API is not supported by the Yoast plugin, or you use other SEO plugin, you can use the @frontity/head-tags package.
Revisiting this thread, I think I forgot something important to mention!
In order to embed the post types – which are the entities that contain the yoast_meta field for post type archives (i.e. the homepage or the archive of a custom post type) – in the REST API responses, you would need to include some code in your WordPress site similar to the following one:
That code adds the type inside the _links field of post entities and makes it embeddable so type entities are included when Frontity makes calls to the WordPress REST API.
I’m trying to use the transformLinks.base property but it doesn’t seem to work, and when I tried to find in the code how that is working, I couldn’t find where that transformation is being done. Could you help me here?
The @frontity/yoast package transforms links inside the useYoastHead hook, defined in /src/hooks/index.ts:
The function transformAllLinks() is defined in /src/utils/index.ts and uses transformLink() – defined in the @frontity/head-tags package – under the hood.
The property state.yoast.transformLinks.base is not documented yet but it is explained in the TSDocs:
WordPress URL base that must be replaced by the Frontity URL base (specified in state.frontity.url). If this value is not set, it is computed from state.source.api.
What’s exactly the problem you have? Is there a way to reproduce it?
I’ve just noticed that we are not saying anything in the Readme about the snippet that needs to be added in PHP, this one: Support for Yoast plugin REST API fields.
Do you guys think that it makes sense to say in the docs that in the future that snippet will be included in the Frontity WordPress Plugin? Or is it better not to mention the Frontity WordPress Plugin?
I don’t completely understand what you’re saying in this post.
By “post types” do you mean Custom Post Types? I can’t find any other reference to the yoast_meta field. Can you explain what that is.
When you refer to “the homepage or the archive of a custom post type” are you intending “homepage” and “archive” to mean the same thing, or are they different things?
I’m also not sure what this means: " That code adds the type inside the _links field of post entities".
It would be great if you could provide more clarity here.