| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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',
- upcoming: 'by-upcoming',
- current: 'by-current',
- currentAndUpcoming: 'by-current-and-upcoming',
- past: 'by-past',
- }
-
- /**
- * 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 = [
- 'sticky',
- 'episode',
- 'artist',
- 'exhibition',
- 'event',
- 'post',
- 'page',
- ]
-
- /**
- * 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.pajth: ${type}`)
- }
- // console.log('type from route:',type)
- return type
- }
-
- const ytThumbnail = (url, desiredSize) => {
- const remove = [
- '',
- 'https:',
- 'http:',
- 'youtu.be',
- 'www.youtube.com',
- 'youtube.com',
- 'embed',
- ]
- const videoId = url
- .split('/')
- .filter(urlSection => !remove.includes(urlSection))
-
- // Uncomment to see what the url transformer is finding
- // console.log('video:', videoId[0])
- let size = 'maxresdefault'
- switch (desiredSize) {
- case 'medium':
- size = 'mqdefault'
- break
- case 'large':
- size = 'hqdefault'
- break
- case 'standard':
- size = 'sddefault'
- break
- case 'max':
- size = 'maxresdefault'
- break
- }
- return `https://img.youtube.com/vi/${videoId[0]}/${size}.jpg`
- }
-
- const formatDate = (unix, includeTime) => {
- const d = new Date(parseInt(unix) * 1000)
- return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
- }
-
- export {
- convertTitleCase,
- dePluralize,
- typeFromRoute,
- sortTypes,
- postTypes,
- ytThumbnail,
- formatDate
- }
|