PageSourceSearch

https://controlealtdelete.nl/wp-content/themes/wings/js/post-meta-insertion.js?ver=1778493803

js controlealtdelete.nl collected 2026-10-02 08:09:25 UTC 3,432 bytes, 123 lines download raw bytes

1/**
2 * Post Meta Insertion
3 *
4 * Dynamically inserts post meta (date and author) after the lede block
5 * or at the top of entry-content if no lede exists
6 */
7
8(function () {
9	'use strict';
10
11	// Function to create the post meta HTML
12	function createPostMetaHTML() {
13		// Get post meta data from WordPress
14		const postDate = document
15			.querySelector('meta[property="article:published_time"]')
16			?.getAttribute('content');
17		const postAuthor = document
18			.querySelector('meta[property="article:author"]')
19			?.getAttribute('content');
20		const authorURL = document
21			.querySelector('meta[name="author-url"]')
22			?.getAttribute('content');
23
24		if (!postDate && !postAuthor) {
25			return null; // No meta data available
26		}
27
28		// Format the date — pick up the document's language so non-English sites
29		// don't get hardcoded en-US dates. Falls back to en-US.
30		let dateHTML = '';
31		if (postDate) {
32			const date = new Date(postDate);
33			const lang = (document.documentElement.lang || 'en-US').replace('_', '-');
34			const formattedDate = date.toLocaleDateString(lang, {
35				year: 'numeric',
36				month: 'long',
37				day: 'numeric',
38			});
39			dateHTML = `<time class="post-date-elegant" datetime="${postDate}">${formattedDate}</time>`;
40		}
41
42		// Create author HTML
43		let authorHTML = '';
44		if (postAuthor) {
45			if (authorURL) {
46				authorHTML = `<span class="post-author-elegant"><a href="${authorURL}" class="post-author-link">${postAuthor}</a></span>`;
47			} else {
48				authorHTML = `<span class="post-author-elegant">${postAuthor}</span>`;
49			}
50		}
51
52		// Create the complete meta HTML
53		return `
54			<div class="post-meta-elegant">
55				<div class="post-meta-elegant-content">
56					${dateHTML}
57					${authorHTML}
58				</div>
59			</div>
60		`;
61	}
62
63	// Function to insert post meta
64	function insertPostMeta() {
65		try {
66			// Skip if compact header already has meta
67			if (document.querySelector('.compact-header-meta')) {
68				return;
69			}
70
71			const entryContent = document.querySelector('.entry-content');
72			if (!entryContent) {
73				return; // No entry content found
74			}
75
76			const postMetaHTML = createPostMetaHTML();
77			if (!postMetaHTML) {
78				return; // No meta data available
79			}
80
81			// Create a temporary container to parse the HTML
82			const tempContainer = document.createElement('div');
83			tempContainer.innerHTML = postMetaHTML.trim();
84			const postMetaElement = tempContainer.firstChild;
85
86			// Ensure the element was created successfully
87			if (!postMetaElement) {
88				return;
89			}
90
91			// Look for the lede block
92			const ledeBlock = entryContent.querySelector('.wings-lede-block');
93
94			if (ledeBlock) {
95				// Insert after the lede block
96				ledeBlock.parentNode.insertBefore(postMetaElement, ledeBlock.nextSibling);
97			} else {
98				// Insert at the top of entry-content
99				entryContent.insertBefore(postMetaElement, entryContent.firstChild);
100			}
101		} catch (error) {
102			// Silently fail if there's an error - don't break the page
103			console.warn('Post meta insertion failed:', error);
104		}
105	}
106
107	// Run when DOM is ready with error handling
108	if (document.readyState === 'loading') {
109		document.addEventListener('DOMContentLoaded', () => {
110			try {
111				insertPostMeta();
112			} catch (error) {
113				console.warn('Post meta insertion failed on DOMContentLoaded:', error);
114			}
115		});
116	} else {
117		try {
118			insertPostMeta();
119		} catch (error) {
120			console.warn('Post meta insertion failed on immediate execution:', error);
121		}
122	}
123})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.