Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
30b67d6
update links to respect primary locale and include prefix
Jan 6, 2026
ad011c6
fix
Jan 6, 2026
3eb44f3
camel case
Jan 6, 2026
37e0308
handle locator slugs
Jan 6, 2026
4277f8f
special handling for DM
Jan 6, 2026
a6547da
comments
Jan 8, 2026
d1fd050
Update component screenshots for visual-editor
github-actions[bot] Jan 8, 2026
68c1bec
refactor: adjust promo content layout (#974)
benlife5 Jan 6, 2026
f3f328a
feat: generate adjusted font fallbacks for smoother font loading (#959)
benlife5 Jan 7, 2026
f637e29
refactor: use reviews from stream (#976)
benlife5 Jan 8, 2026
703360a
feat: added open in new tab and center aligned the secondary footer (…
rkeerthient Jan 8, 2026
216e150
feat: renamed media orientation, fixed truncate in event section (#971)
rkeerthient Jan 8, 2026
dc3b13d
fix: line height in rich text and reduced event description (#972)
rkeerthient Jan 8, 2026
60c48a6
Merge remote-tracking branch 'origin' into update-links
Jan 8, 2026
5e5b307
Update component screenshots for visual-editor
github-actions[bot] Jan 8, 2026
e05db4b
fix
Jan 8, 2026
2bcf97c
Update component screenshots for visual-editor
github-actions[bot] Jan 8, 2026
1412778
fix
Jan 8, 2026
005e800
fix tests
Jan 8, 2026
bcca578
Update component screenshots for visual-editor
github-actions[bot] Jan 8, 2026
900dc35
Update component screenshots for visual-editor
github-actions[bot] Jan 8, 2026
174e4a9
fix comment
Jan 9, 2026
eda2263
comments
Jan 9, 2026
f8610d6
Merge branch 'main' into update-links
asanehisa Jan 21, 2026
c8583b3
add helpers / adjust tests
asanehisa Jan 22, 2026
d13ea0b
Automated linting/prettier update
github-actions[bot] Jan 22, 2026
3d9a2fc
undo change in locator
asanehisa Jan 22, 2026
501e6d8
Merge branch 'update-links' of https://github.com/yext/visual-editor …
asanehisa Jan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
384 changes: 291 additions & 93 deletions packages/visual-editor/src/utils/getLocationPath.test.ts

Large diffs are not rendered by default.

29 changes: 23 additions & 6 deletions packages/visual-editor/src/utils/getLocationPath.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { normalizeSlug } from "./slugifier.ts";
import { AddressType } from "@yext/pages-components";
import { StreamDocument } from "./applyTheme.ts";
import {
getIsPrimaryLocale,
getLocalePrefix,
getPageSetConfig,
} from "./pageset.ts";

export interface LocationDocument extends StreamDocument {
id: string;
slug?: string;
address?: AddressType;
}

// Returns the path for a location document, applying locale prefixes as needed.
// If slug is present, uses slug. Otherwise, constructs path from address or id.
// Should be used as a fallback when URL templates are not available.
export const getLocationPath = (
location: LocationDocument,
relativePrefixToRoot: string = ""
Expand All @@ -16,6 +24,7 @@ export const getLocationPath = (
throw new Error("Could not resolve location path.");
}

// If there's a slug, don't apply locale prefix to it
if (location.slug) {
return `${relativePrefixToRoot}${location.slug}`;
}
Expand All @@ -25,14 +34,22 @@ export const getLocationPath = (
throw new Error("Missing locale for getLocationPath");
}

const isPrimaryLocale =
location.__?.isPrimaryLocale === true ||
(location.__?.isPrimaryLocale === undefined && location.locale === "en");
const pageSetConfig = getPageSetConfig(location?._pageset);
const isPrimaryLocale = getIsPrimaryLocale({
locale,
pageSetConfig,
fallbackIsPrimaryLocale: location.__?.isPrimaryLocale,
});
const localePrefix = getLocalePrefix({
locale,
isPrimaryLocale,
includeLocalePrefixForPrimaryLocale:
pageSetConfig?.includeLocalePrefixForPrimaryLocale,
});

const localePath = isPrimaryLocale ? "" : `${locale}/`;
const path = location.address
? `${localePath}${location.address.region}/${location.address.city}/${location.address.line1}`
: `${localePath}${location.id}`;
? `${localePrefix}${location.address.region}/${location.address.city}/${location.address.line1}`
: `${localePrefix}${location.id}`;

return `${relativePrefixToRoot}${normalizeSlug(path)}`;
};
20 changes: 11 additions & 9 deletions packages/visual-editor/src/utils/mergeMeta.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { StreamDocument } from "./applyTheme.ts";
import { getIsPrimaryLocale, getPageSetConfig } from "./pageset.ts";

/**
* Merges a profile object with meta fields from the streamDocument such as __, _pageset, and locale.

* @param {Object} profile
* @param {Object} streamDocument
* @returns {Object}
*/
export function mergeMeta(profile: any, streamDocument: any): any {
export function mergeMeta(profile: any, streamDocument: StreamDocument): any {
const locale: string = profile?.meta?.locale || streamDocument?.locale;

let isPrimaryLocale: boolean;
if (profile?.meta?.isPrimaryLocale === true) {
isPrimaryLocale = true;
} else if (profile?.meta?.isPrimaryLocale === false) {
isPrimaryLocale = false;
} else {
isPrimaryLocale = locale === "en";
}
const pageSetConfig = getPageSetConfig(streamDocument?._pageset);
const fallbackIsPrimaryLocale = streamDocument.__?.isPrimaryLocale;
const isPrimaryLocale = getIsPrimaryLocale({
locale,
pageSetConfig,
fallbackIsPrimaryLocale,
});

return {
locale: locale,
Expand Down
53 changes: 53 additions & 0 deletions packages/visual-editor/src/utils/pageset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// based on Config in https://gerrit.yext.com/plugins/gitiles/alpha/+/refs/heads/master/src/com/yext/publish/pagesets/resource.proto#173
export type PageSetConfig = {
primaryLocale?: string;
urlTemplate?: {
primary?: string;
alternate?: string;
};
includeLocalePrefixForPrimaryLocale?: boolean;
[key: string]: any; // allow any other fields
};

// Parses _pageset (string or object) and returns the config object.
export const getPageSetConfig = (pageset: any): PageSetConfig => {
const pageSetJson =
typeof pageset === "string"
? JSON.parse(pageset || "{}")
: (pageset as { config?: PageSetConfig }) || {};
return pageSetJson?.config || {};
};

// Determines if the locale is primary, falling back if needed.
export const getIsPrimaryLocale = ({
locale,
pageSetConfig,
fallbackIsPrimaryLocale = false,
}: {
locale?: string;
pageSetConfig?: PageSetConfig;
fallbackIsPrimaryLocale?: boolean;
}): boolean => {
return !!pageSetConfig?.primaryLocale
? locale === pageSetConfig.primaryLocale
: fallbackIsPrimaryLocale;
};

/**
* Returns the locale prefix based on pageset locale, isPrimaryLocale, and includeLocalePrefixForPrimaryLocale.
* If the locale is not primary, always includes the locale prefix.
* If the locale is primary, includes the locale prefix only if includeLocalePrefixForPrimaryLocale is true.
*/
export const getLocalePrefix = ({
locale,
isPrimaryLocale,
includeLocalePrefixForPrimaryLocale,
}: {
locale: string;
isPrimaryLocale?: boolean;
includeLocalePrefixForPrimaryLocale?: boolean;
}): string => {
return !isPrimaryLocale || includeLocalePrefixForPrimaryLocale
? `${locale}/`
: "";
};
Loading
Loading