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

MWPW-162839: Move title-append to loadArea #3341

Merged
merged 8 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions libs/features/title-append/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions libs/features/title-append/title-append.js

This file was deleted.

16 changes: 11 additions & 5 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ export function appendHtmlToCanonicalUrl() {
canonEl.setAttribute('href', `${canonEl.href}.html`);
}

export function appendSuffixToTitles() {
const appendage = getMetadata('title-append');
if (!appendage) return;
document.title = `${document.title} ${appendage}`;
const ogTitleEl = document.querySelector('meta[property="og:title"]');
if (ogTitleEl) ogTitleEl.setAttribute('content', document.title);
const twitterTitleEl = document.querySelector('meta[name="twitter:title"]');
if (twitterTitleEl) twitterTitleEl.setAttribute('content', document.title);
}

export function appendHtmlToLink(link) {
const { useDotHtml } = getConfig();
if (!useDotHtml) return;
Expand Down Expand Up @@ -1278,11 +1288,6 @@ function decorateDocumentExtras() {

async function documentPostSectionLoading(config) {
decorateFooterPromo();

const appendage = getMetadata('title-append');
if (appendage) {
import('../features/title-append/title-append.js').then((module) => module.default(appendage));
}
if (getMetadata('seotech-structured-data') === 'on' || getMetadata('seotech-video-url')) {
import('../features/seotech/seotech.js').then((module) => module.default(
{ locationUrl: window.location.href, getMetadata, createTag, getConfig },
Expand Down Expand Up @@ -1375,6 +1380,7 @@ export async function loadArea(area = document) {
if (isDoc) {
await checkForPageMods();
appendHtmlToCanonicalUrl();
appendSuffixToTitles();
}
const config = getConfig();

Expand Down
3 changes: 0 additions & 3 deletions test/features/title-append/mocks/head-social.html

This file was deleted.

1 change: 0 additions & 1 deletion test/features/title-append/mocks/head.html

This file was deleted.

39 changes: 0 additions & 39 deletions test/features/title-append/title-append.test.js

This file was deleted.

6 changes: 4 additions & 2 deletions test/utils/mocks/head-title-append.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<meta name="title-append" content="NOODLE">
<meta name="title-append" content="NOODLE" />
<meta property="og:title" content="Document Title" />
<meta name="twitter:title" content="Document Title" />
<title>Document Title</title>
<link rel="icon" href="data:,">
<link rel="icon" href="data:," />
5 changes: 4 additions & 1 deletion test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,18 +719,21 @@ describe('Utils', () => {
});
});

// MARK: title-append
describe('title-append', async () => {
beforeEach(async () => {
document.head.innerHTML = await readFile({ path: './mocks/head-title-append.html' });
});
it('should append to title using string from metadata', async () => {
const expected = 'Document Title NOODLE';
await utils.loadArea();
await waitFor(() => document.title === expected, 2000);
expect(document.title).to.equal(expected);
expect(document.querySelector('meta[property="og:title"]')?.getAttribute('content'), expected);
expect(document.querySelector('meta[name="twitter:title"]')?.getAttribute('content'), expected);
});
});

// MARK: seotech
describe('seotech', async () => {
beforeEach(async () => {
window.lana = { log: (msg) => console.error(msg) };
Expand Down
Loading