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

Fix related posts #4138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .cache/related-posts-1724946364101.json

This file was deleted.

1 change: 1 addition & 0 deletions .cache/related-posts-1731013298646.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions data/assetPaths.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"admin.map": "/assets/js/admin-TH6ADBUC.js.map",
"app.js": "/assets/js/app-XKFC5Y7M.js",
"app.map": "/assets/js/app-XKFC5Y7M.js.map",
"styles.css": "/assets/styles/styles-VW6JU45O.css",
"styles.map": "/assets/styles/styles-VW6JU45O.css.map"
}

"styles.css": "/assets/styles/styles-Z2E3ARAM.css",
"styles.map": "/assets/styles/styles-Z2E3ARAM.css.map"
}
15 changes: 14 additions & 1 deletion lib/related_posts/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ class Cache {
// @return [object] JSON data from the most recent cache
exists = () => this.files().length > 0

mostRecentFile = () => this.files()[0]

mostRecentFilePath = () => `${ this.dir }/${ this.mostRecentFile() }`

// @return [object] JSON data from the most recent cache
current = () => JSON.parse(fs.readFileSync(`${ this.dir }/${this.files()[0]}`))
current = () => {
if (this.mostRecentFile() === undefined) {
return false
}
return JSON.parse(fs.readFileSync(this.mostRecentFilePath()))
}

// Deletes all caches except the cache with the most future date
// @return [undefined]
Expand All @@ -51,6 +60,10 @@ class Cache {
// @return [undefined]
deleteAll = () => this.files().forEach(file => fs.unlinkSync(`${ this.dir }/${file}`))

// Saves data to a cache and deletes everything but the most recent cache
// @param data [object] data to write to the file
// @param ts [number, string, undefined] Timestamp to assign to the filename
// @return [undefined]
saveAndClean = (data={}, ts=undefined) => {
this.save(data, ts)
this.deleteOutdated()
Expand Down
4 changes: 2 additions & 2 deletions lib/related_posts/related_posts_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RelatedPostsGenerator {
}

exitEarly () {
return this.#cache && !this.#didFilesChange() && this.#relatedPostsCache.exists()
return this.#cache && !this.#didPostFilesChange() && this.#relatedPostsCache.exists()
}

// @todo This doesn't apply tiebreakers for tied scores - ideally it would ensure
Expand All @@ -68,7 +68,7 @@ class RelatedPostsGenerator {
}
}

#didFilesChange () { /* eslint-disable-line class-methods-use-this */
#didPostFilesChange () { /* eslint-disable-line class-methods-use-this */
const differ = process.env.CI ? new CommitDiffer : new Differ
const changedFiles = differ.changedFiles();
const changedPosts = changedFiles.filter((f) => f.startsWith('content/posts') && f.endsWith('.md'))
Expand Down
Loading