project-data.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. hexo.extend.helper.register('getProjectDataHTML', function(pages){
  2. var projects = [];
  3. var project_data = []
  4. var s = ""
  5. pages.forEach(page => {
  6. if(page.layout == "project") projects.push(page);
  7. });
  8. projects.forEach(project => {
  9. var tags = [];
  10. var contacts = []
  11. project.tags.forEach(tag => {
  12. tags.push(tag.name);
  13. })
  14. project.contacts.forEach(contact => {
  15. contacts.push({ name: contact.name, url: contact.url });
  16. })
  17. project_data.push({
  18. title: project.title,
  19. folder: project.folder,
  20. permalink: project.permalink,
  21. description: project.description,
  22. date: project.date,
  23. cover_image: project.cover_image,
  24. hero_image: project.hero_image,
  25. thumbnail_image: project.thumbnail_image,
  26. website: project.website,
  27. featured: project.featured,
  28. tags: tags,
  29. start_date: project.start_date,
  30. end_date: project.end_date,
  31. contact_types: project.contact_types,
  32. contacts : contacts,
  33. text: project.text
  34. })
  35. })
  36. for (let i = 0; i < project_data.length; i++) {
  37. s += JSON.stringify(project_data[i]);
  38. if(i < project_data.length -1) s += ', ';
  39. }
  40. return `<script>var projectsList = [${s}]</script>`
  41. });