jekyll.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. module.exports = function jekyll(renderDocsProcessor) {
  2. return {
  3. name: 'jekyll',
  4. description: 'Create jekyll includes',
  5. $runAfter: ['paths-computed'],
  6. $runBefore: ['rendering-docs'],
  7. $process: function(docs) {
  8. var currentVersion = renderDocsProcessor.extraData.version.current.name;
  9. // pretty up and sort the docs object for menu generation
  10. docs = docs.filter(function(doc) {
  11. return (!!doc.name && !!doc.outputPath) || doc.docType === 'index-page';
  12. });
  13. docs.sort(function(a, b) {
  14. textA = a.name ? a.name.toUpperCase() : '';
  15. textB = b.name ? b.name.toUpperCase() : '';
  16. return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
  17. });
  18. docs.forEach(function(doc, i) {
  19. docs[i].URL = doc.outputPath.replace('docs//', 'docs/')
  20. .replace('/index.md', '')
  21. .replace('//home/ubuntu/ionic/src', '')
  22. .replace('//', '/')
  23. .replace('content/', '');
  24. if (docs[i].relativePath) {
  25. docs[i].relativePath = doc.relativePath
  26. .replace('/home/ubuntu/ionic', '');
  27. }
  28. if (docs[i].href) {
  29. docs[i].href = doc.href.replace('content/', '');
  30. }
  31. if (docs[i].description) {
  32. docs[i].description = docs[i].description.replace(/(\#\#\#).+/g, (section) => {
  33. const title = section.replace(/^(\#+\s?)/, '');
  34. const segment = title.replace(/[^a-zA-Z0-9]+/g, '-').toLowerCase();
  35. return `\n<h3><a class="anchor" name="${segment}" href="#${segment}">${title}</a></h3>\n`;
  36. });
  37. }
  38. });
  39. docs.push({
  40. docType: 'api-menu',
  41. id: 'api-menu',
  42. template: 'api_menu.template.html',
  43. outputPath: 'content/_includes/fluid/api_menu.html'
  44. });
  45. docs.push({
  46. docType: 'api-menu-flat-version',
  47. id: 'api-menu-flat-version',
  48. template: 'api_menu_flat_version.template.html',
  49. outputPath: 'content/_includes/fluid/api_menu_flat_' + currentVersion +
  50. '.html'
  51. });
  52. docs.push({
  53. docType: 'api-version-select',
  54. id: 'api-version-select',
  55. template: 'api_version_select.template.html',
  56. outputPath: 'content/_includes/fluid/api_version_select.html'
  57. });
  58. // returning docs will replace docs object in the next process
  59. return docs;
  60. }
  61. };
  62. };