Filter out draft posts & empty categories
This commit is contained in:
parent
0bc6b528b2
commit
a685051187
2 changed files with 14 additions and 6 deletions
11
src/App.js
11
src/App.js
|
|
@ -20,7 +20,7 @@ import ServiceWorkerNotifications from './components/ServiceWorkerNotifications'
|
|||
import AOS from './components/AOS'
|
||||
import Spinner from './components/Spinner'
|
||||
import data from './data.json'
|
||||
import { documentHasTerm } from './util/collection'
|
||||
import { documentHasTerm, getCollectionTerms } from './util/collection'
|
||||
|
||||
class App extends Component {
|
||||
state = {
|
||||
|
|
@ -69,8 +69,13 @@ class App extends Component {
|
|||
headerScripts
|
||||
} = globalSettings
|
||||
|
||||
const posts = this.getDocuments('posts')
|
||||
const postCategories = this.getDocuments('postCategories')
|
||||
const posts = this.getDocuments('posts').filter(
|
||||
post => post.status !== 'Draft'
|
||||
)
|
||||
const categoriesFromPosts = getCollectionTerms(posts, 'categories')
|
||||
const postCategories = this.getDocuments('postCategories').filter(
|
||||
category => categoriesFromPosts.indexOf(category.title.toLowerCase()) >= 0
|
||||
)
|
||||
|
||||
return (
|
||||
<Router>
|
||||
|
|
|
|||
|
|
@ -14,8 +14,11 @@ export const getCollectionTerms = (
|
|||
let terms = collection
|
||||
.filter(collectionItem => collectionItem[taxonomyName])
|
||||
.reduce((acc, collectionItem) => {
|
||||
const termString = collectionItem[taxonomyName]
|
||||
const collectionItemTerms = termString.split(',').map(term => term.trim())
|
||||
const termField = collectionItem[taxonomyName]
|
||||
const collectionItemTerms =
|
||||
typeof termField === 'string'
|
||||
? termField.split(',').map(term => _kebabCase(term.trim()))
|
||||
: termField.map(term => _kebabCase(Object.values(term)[0]))
|
||||
return _uniq([...acc, ...collectionItemTerms])
|
||||
}, [])
|
||||
.sort()
|
||||
|
|
@ -30,6 +33,6 @@ export const documentHasTerm = (doc, taxonomyName, term) => {
|
|||
typeof termField === 'string'
|
||||
? termField.split(',').map(term => _kebabCase(term))
|
||||
: termField.map(term => _kebabCase(Object.values(term)[0]))
|
||||
// console.log(terms.includes(_kebabCase(term)))
|
||||
|
||||
return terms.includes(_kebabCase(term))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue