mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Use whole word regex matches for descriptions
This commit is contained in:
parent
fa222d3116
commit
d434b19c9b
5 changed files with 74 additions and 41 deletions
|
|
@ -6,6 +6,10 @@ import { byTimeThenNull } from './sort-list.js'
|
|||
import { getVideoEndpoint } from './app-derived.js'
|
||||
import parseGithubDate from './parse-github-date'
|
||||
|
||||
export function matchesWholeWord (needle, haystack) {
|
||||
return new RegExp('\\b' + needle + '\\b').test(haystack)
|
||||
}
|
||||
|
||||
const videoFeaturesApp = function (app, video) {
|
||||
const appFuzzyName = app.name.toLowerCase()
|
||||
if (video.title.toLowerCase().includes(appFuzzyName)) return true
|
||||
|
|
@ -14,7 +18,7 @@ const videoFeaturesApp = function (app, video) {
|
|||
|
||||
if (appIsInTimestamps) return true
|
||||
|
||||
if (video.description.toLowerCase().includes(appFuzzyName)) return true
|
||||
if (matchesWholeWord(appFuzzyName, video.description.toLowerCase())) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import homebrewList from '~/static/homebrew-list.json'
|
|||
|
||||
import { byTimeThenNull } from '~/helpers/sort-list.js'
|
||||
|
||||
export const allVideoList = [
|
||||
export const allVideoAppsList = [
|
||||
...appList.sort(byTimeThenNull),
|
||||
...gameList,
|
||||
]
|
||||
|
|
|
|||
57
helpers/related.js
Normal file
57
helpers/related.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { allVideoAppsList } from '~/helpers/get-list.js'
|
||||
import videoList from '~/static/video-list.json'
|
||||
|
||||
export function matchesWholeWord (needle, haystack) {
|
||||
return new RegExp('\\b' + needle + '\\b').test(haystack)
|
||||
}
|
||||
|
||||
export function appsRelatedToVideo ( video ) {
|
||||
const relatedApps = []
|
||||
|
||||
// Find the apps listed in this video
|
||||
for (const app of allVideoAppsList) {
|
||||
// Skip this app if it's not listed in the videos apps
|
||||
if (!video.apps.includes(app.slug)) continue
|
||||
|
||||
// Add this app to our featured app list
|
||||
relatedApps.push(app)
|
||||
}
|
||||
|
||||
return relatedApps
|
||||
}
|
||||
|
||||
export function videosRelatedToVideo ( video ) {
|
||||
const relatedVideos = []
|
||||
|
||||
const featuredApps = appsRelatedToVideo( video )
|
||||
|
||||
// Find other videos that also feature this video's app
|
||||
for (const otherVideo of videoList) {
|
||||
for (const app of featuredApps) {
|
||||
// Skip if this app is not in the other video's apps
|
||||
if (!otherVideo.apps.includes(app.slug)) continue
|
||||
|
||||
// Skip if the other video is, in fact, this video
|
||||
if (otherVideo.slug === video.slug) continue
|
||||
|
||||
// Add this video to our related videos list
|
||||
relatedVideos.push(otherVideo)
|
||||
}
|
||||
}
|
||||
|
||||
return relatedVideos
|
||||
}
|
||||
|
||||
|
||||
export function videosRelatedToApp ( app ) {
|
||||
const relatedVideos = []
|
||||
|
||||
// Find other videos that also feature this video's app
|
||||
for (const video of videoList) {
|
||||
if (!video.apps.includes(app.slug)) continue
|
||||
|
||||
relatedVideos.push(video)
|
||||
}
|
||||
|
||||
return relatedVideos
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue