-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Add author work #3257
Add author work #3257
Conversation
db/model/Gdoc/GdocAuthor.ts
Outdated
_loadSubclassAttachments = async (): Promise<void> => { | ||
if (!this.content.title) return | ||
const knex = db.knexInstance() | ||
|
||
this.latestWorkLinks = await getLatestWorkByAuthor( | ||
knex, | ||
this.content.title | ||
) | ||
if (!this.latestWorkLinks) return | ||
|
||
// We want to load additional image filenames from the referenced | ||
// latest work links. We're not relying here on the Link | ||
// infrastructure as we don't yet have a good way of cleaning up | ||
// obsolete links from the latest work section. Usually the links | ||
// originating from a gdoc are cleaned up when updating/deleting it, but | ||
// here the links from the latest section will change independently of a | ||
// manual authoring and admin action, so they'll end up being stale | ||
// until the author page is updated again. | ||
const latestWorkImageFilenames = this.latestWorkLinks | ||
.map((d) => d["featured-image"]) | ||
.filter(Boolean) | ||
|
||
// Load the image metadata for the latest work images | ||
return super.loadImageMetadata(latestWorkImageFilenames) |
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.
@ikesau I'd be curious to hear whether this adjustment to parsing images in a block, whose content is dynamically generated, fits your mental model of image handling.
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.
I don't understand this comment - can you give me a bit of context for this one? Is this a concern because of lightning baking? Why can we not just iterate over the latest work and collect the featured-images?
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.
Why can we not just iterate over the latest work and collect the featured-images?
@danyx23 I'm assuming you're referring to
owid-grapher/db/model/Gdoc/GdocBase.ts
Lines 276 to 286 in 904b82c
get linkedImageFilenames(): string[] { | |
// The typing logic is a little strange here | |
// `featured-image` isn't guaranteed to be on all types of Gdoc (it's a GdocPost thing) | |
// but we try (and then filter nulls) because we need featured images if we're using prominent links | |
// even if this method is being called on a GdocFaq (for example) | |
const featuredImages = Object.values(this.linkedDocuments) | |
.map((d) => d["featured-image"]) | |
.filter((filename?: string): filename is string => !!filename) | |
return [...this.filenames, ...featuredImages] | |
} |
In this snippet this.linkedDocuments
originate from this.links
, which is populated in parallel to Link.createFromUrl
calls, which create rows in the posts_gdocs_links
table.
These links only get refreshed when updating/deleting a gdoc in the admin:
owid-grapher/adminSiteServer/apiRouter.ts
Lines 2465 to 2469 in 904b82c
await Link.delete({ | |
source: { | |
id: id, | |
}, | |
}) |
The problem is that there won't be an admin action for every update to the latest work block, which is updated dynamically whenever a new article by a given author is published/unpublished. So the posts_gdocs_links
table will gradually fall out of sync.
By contrast, the featured work block is manually updated from content in the gdoc itself, so modifying the block necessarily updates the posts_gdocs_links
table.
6c308b6
to
c85a36d
Compare
c85a36d
to
5ccd633
Compare
5ccd633
to
0823eff
Compare
0823eff
to
70ed774
Compare
70ed774
to
510ce90
Compare
510ce90
to
ae3fbc5
Compare
ae3fbc5
to
58e5748
Compare
58e5748
to
8941b4e
Compare
00184cc
to
1512949
Compare
1512949
to
97e902a
Compare
a09413d
to
904b82c
Compare
904b82c
to
ac52db5
Compare
ac52db5
to
2e9fee4
Compare
staging preview, gdoc
👉 See this comment for some of the more structural decisions I made.
Only consider the "🌑 Dark launch" scope from the tracking issue