Skip to content

Commit

Permalink
fix(yoast): do not use canonical from yoast_meta (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Jul 31, 2019
1 parent bd8c6dc commit b698670
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
19 changes: 4 additions & 15 deletions packages/yoast/src/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Yoast from "../../types";
import { getEntity, getSocialDefaults } from "./utils";
import { getEntity, getSocialDefaults, getPathname } from "./utils";
import {
homeTitle,
entityTitle,
Expand Down Expand Up @@ -71,24 +71,13 @@ const state: Yoast["state"]["yoast"] = {
* @param state Frontity state
* @returns Current route's canonical link
*/
canonical: ({ state }) => {
const data = state.source.get(state.router.link);
const entity = getEntity({ state, data });

const defaultCanonical = `${state.frontity.url}${state.router.link}`;

if (!entity) return defaultCanonical;

const yoastCanonical =
entity.yoast_meta && entity.yoast_meta.yoast_wpseo_canonical;

return yoastCanonical || defaultCanonical;
},
canonical: ({ state }) =>
`${state.frontity.url}${getPathname(state.router.link)}`,

/**
* Derived value that shows the featured image's URL (if link is a post)
* @param state Frontity state
* @returns Current route's canonical link
* @returns Current route's featured image URL
*/
image: ({ state }) => {
const data = state.source.get(state.router.link);
Expand Down
2 changes: 1 addition & 1 deletion packages/yoast/src/state/titles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { State } from "frontity/types";
import { Data, Author } from "@frontity/source";
import humanize from "string-humanize";
import Yoast, { YoastMeta } from "../../types";
import Yoast from "../../types";
import { getEntity, appendPage, getPage, hasName } from "./utils";

export const dateTitle = ({
Expand Down
9 changes: 5 additions & 4 deletions packages/yoast/src/state/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ export const getSocialDefaults = ({ state }): YoastSocialDefaults => {
return {};
};

export const getPage = route => {
// get pathname from route
export const getPathname = route => {
const [, pathname] = /^(?:(?:[^:/?#]+):)?(?:\/\/(?:[^/?#]*))?([^?#]*)/.exec(
route
);
return pathname;
};

const [, page] = /^(?:.*)page\/(\d+)\/?(\?.*)?$/.exec(pathname) || [
export const getPage = route => {
const [, page] = /^(?:.*)page\/(\d+)\/?(\?.*)?$/.exec(getPathname(route)) || [
null,
"1"
];

return parseInt(page, 10);
};

Expand Down

0 comments on commit b698670

Please sign in to comment.