-
Notifications
You must be signed in to change notification settings - Fork 1
fix(og): news permalink resolves share image via rollup parent POI (#475) #479
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2635,17 +2635,18 @@ async function findItemBySlugs(type, poiSlug, titleSlug) { | |||||||||||||||||||||||
| `, [poi.id]); | ||||||||||||||||||||||||
| rows = q.rows; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| const poiIds = await getRollupPoiIds(pool, poi.id); | ||||||||||||||||||||||||
| const q = await pool.query(` | ||||||||||||||||||||||||
| SELECT n.id, n.title, n.summary, n.source_url, n.source_name, n.news_type, | ||||||||||||||||||||||||
| n.publication_date, n.collection_date, n.image_url, p.name AS poi_name, p.id AS poi_id, | ||||||||||||||||||||||||
| COALESCE(json_agg(json_build_object('url', u.url, 'source_name', u.source_name)) FILTER (WHERE u.id IS NOT NULL), '[]'::json) AS additional_urls | ||||||||||||||||||||||||
| FROM poi_news n | ||||||||||||||||||||||||
| JOIN pois p ON n.poi_id = p.id | ||||||||||||||||||||||||
| LEFT JOIN poi_news_urls u ON u.news_id = n.id | ||||||||||||||||||||||||
| WHERE n.poi_id = $1 AND n.moderation_status IN ('published', 'auto_approved') | ||||||||||||||||||||||||
| WHERE n.poi_id = ANY($1) AND n.moderation_status IN ('published', 'auto_approved') | ||||||||||||||||||||||||
| GROUP BY n.id, p.name, p.id | ||||||||||||||||||||||||
| ORDER BY COALESCE(n.publication_date, n.collection_date) DESC | ||||||||||||||||||||||||
| `, [poi.id]); | ||||||||||||||||||||||||
| `, [poiIds]); | ||||||||||||||||||||||||
| rows = q.rows; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -2803,7 +2804,7 @@ app.use(async (req, res, next) => { | |||||||||||||||||||||||
| const safeDesc = escapeHtml(description.length > 200 ? description.substring(0, 197) + '...' : description); | ||||||||||||||||||||||||
| // Image priority: source article image, then POI primary photo, then brand. | ||||||||||||||||||||||||
| const sourceImage = isUsableSourceImage(item.image_url) ? item.image_url : null; | ||||||||||||||||||||||||
| const ogImage = escapeHtml(sourceImage || await resolvePoiOgImage(item.poi_id, baseUrl)); | ||||||||||||||||||||||||
| const ogImage = escapeHtml(sourceImage || await resolvePoiOgImage(item._poi.id, baseUrl)); | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While falling back to the parent POI's image ( We can implement a tiered fallback strategy:
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const indexPath = path.join(staticPath, 'index.html'); | ||||||||||||||||||||||||
| let html = await fs.readFile(indexPath, 'utf-8'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event branch of
findItemBySlugs(lines 2623–2636) suffers from the exact same issue as the news branch. If an event is rolled up to a parent POI (boundary/org), trying to resolve its permalink via the parent POI's slug will fail because the query strictly filters onWHERE e.poi_id = $1.To match the events API and support rolled-up events, the event branch should also be updated to use
getRollupPoiIdsand check(e.poi_id = ANY($1) OR e.venue_poi_id = ANY($1)).Here is how the event branch should be refactored: