| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const convertTitleCase = (type) => {
- if(typeof type !== 'string') return ''
- return type.charAt(0).toUpperCase() + type.slice(1)
- }
-
- const dePluralize = type => {
- return type[type.length - 1] === 's' ? type.slice(0, -1) : type
- }
-
- const sortTypes = {
- alpha: 'by-alpha',
- recent: 'by-recent',
- material: 'by-material',
- artist: 'by-artist',
- episode: 'by-episode',
- }
-
- /**
- * A list of custom post types used to dispatch vuex actions
- * This makes ALL post type modules available for the
- * list and single components to request data
- */
- const postTypes = [
- 'episodes',
- 'artists',
- 'exhibitions',
- 'events',
- 'posts',
- 'pages',
- ]
-
- /**
- * Type assigned from Route :type
- * In case of failure, tries to derive type
- * matching pieces to postTypes array
- */
- const typeFromRoute = route => {
- let type = route.params.type ? route.params.type : route.fullPath.split('/')
-
- if(!route.params.type) {
- // Remove blank path sections and match to postTypes array
- type = type
- .filter(pathSection => pathSection != '')
- .filter(pathSection => postTypes.includes(pathSection))
-
- // Only take the first match
- type = type[0]
- console.log(`type derived from route.path: ${type}`)
- }
-
- return type
- }
-
- export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes }
|