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

Fixed Brief Description Popover extraction Issue #1278

Merged
merged 11 commits into from
Oct 12, 2024
10 changes: 9 additions & 1 deletion www/js/lib/popovers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@ function getArticleLede (href, baseUrl, articleDocument, archive) {

// Helper function to clean up the lede content
function cleanUpLedeContent (node) {
// Define an array of exclusion filters
// (note `.exclude-this-class` is a dummy class used as an example for any future exclusion filters)
const exclusionFilters = ['#pcs-edit-section-title-description', '.exclude-this-class'];
// Construct the `:not()` CSS exclusion selector list
const notSelector = exclusionFilters.map(filter => `:not(${filter})`).join('');

// Remove all standalone style elements from the given DOM node, because their content is shown by innerText and textContent
const styleElements = Array.from(node.querySelectorAll('style'));
styleElements.forEach(style => {
style.parentNode.removeChild(style);
});
const paragraphs = Array.from(node.querySelectorAll('p'));
// Apply this style-based exclusion filter to remove unwanted paragraphs in the popover
const paragraphs = Array.from(node.querySelectorAll(`p${notSelector}`));

// Filter out empty paragraphs or those with less than 50 characters
Jaifroid marked this conversation as resolved.
Show resolved Hide resolved
const parasWithContent = paragraphs.filter(para => {
// DEV: Note that innerText is not supported in Firefox OS, so we need to use textContent as a fallback
Expand Down
Loading