Fix language filtering for feeds (#5026)
* Fix language filtering for feeds * Simplify logiczio/stable
parent
e51eb391df
commit
0a75969475
|
@ -392,27 +392,20 @@ export class FeedTuner {
|
||||||
slices: FeedViewPostsSlice[],
|
slices: FeedViewPostsSlice[],
|
||||||
_dryRun: boolean,
|
_dryRun: boolean,
|
||||||
): FeedViewPostsSlice[] => {
|
): FeedViewPostsSlice[] => {
|
||||||
const candidateSlices = slices.slice()
|
|
||||||
|
|
||||||
// early return if no languages have been specified
|
// early return if no languages have been specified
|
||||||
if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) {
|
if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) {
|
||||||
return slices
|
return slices
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < slices.length; i++) {
|
const candidateSlices = slices.filter(slice => {
|
||||||
let hasPreferredLang = false
|
for (const item of slice.items) {
|
||||||
for (const item of slices[i].items) {
|
|
||||||
if (isPostInLanguage(item.post, preferredLangsCode2)) {
|
if (isPostInLanguage(item.post, preferredLangsCode2)) {
|
||||||
hasPreferredLang = true
|
return true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if item does not fit preferred language, remove it
|
// if item does not fit preferred language, remove it
|
||||||
if (!hasPreferredLang) {
|
return false
|
||||||
candidateSlices.splice(i, 1)
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the language filter cleared out the entire page, return the original set
|
// if the language filter cleared out the entire page, return the original set
|
||||||
// so that something always shows
|
// so that something always shows
|
||||||
|
|
Loading…
Reference in New Issue