NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

helpers.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const convertTitleCase = (type) => {
  2. if(typeof type !== 'string') return ''
  3. return type.charAt(0).toUpperCase() + type.slice(1)
  4. }
  5. const dePluralize = type => {
  6. return type[type.length - 1] === 's' ? type.slice(0, -1) : type
  7. }
  8. const sortTypes = {
  9. alpha: 'by-alpha',
  10. recent: 'by-recent',
  11. material: 'by-material',
  12. artist: 'by-artist',
  13. episode: 'by-episode',
  14. }
  15. /**
  16. * A list of custom post types used to dispatch vuex actions
  17. * This makes ALL post type modules available for the
  18. * list and single components to request data
  19. */
  20. const postTypes = [
  21. 'episodes',
  22. 'artists',
  23. 'exhibitions',
  24. 'events',
  25. 'posts',
  26. 'pages',
  27. ]
  28. /**
  29. * Type assigned from Route :type
  30. * In case of failure, tries to derive type
  31. * matching pieces to postTypes array
  32. */
  33. const typeFromRoute = route => {
  34. let type = route.params.type ? route.params.type : route.fullPath.split('/')
  35. if(!route.params.type) {
  36. // Remove blank path sections and match to postTypes array
  37. type = type
  38. .filter(pathSection => pathSection != '')
  39. .filter(pathSection => postTypes.includes(pathSection))
  40. // Only take the first match
  41. type = type[0]
  42. console.log(`type derived from route.path: ${type}`)
  43. }
  44. return type
  45. }
  46. export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes }