create_github_page.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const path = require('path');
  2. const fs = require("fs");
  3. const fsp = fs.promises;
  4. const JSON5 = require('json5');
  5. function toCode(files, data){
  6. let code = "";
  7. {
  8. let urls = data.map(e => e.url);
  9. let unhandled = [];
  10. for(let file of files){
  11. let isHandled = false;
  12. for(let url of urls){
  13. if(file.indexOf(url) !== -1){
  14. isHandled = true;
  15. }
  16. }
  17. if(!isHandled){
  18. unhandled.push(file);
  19. }
  20. }
  21. unhandled = unhandled
  22. .filter(file => file.indexOf(".html") > 0)
  23. .filter(file => file !== "page.html");
  24. // for(let file of unhandled){
  25. // unhandledCode += `
  26. // <a href="${file}" class="unhandled">${file}</a>
  27. // `;
  28. // }
  29. }
  30. const rows = [];
  31. let row = [];
  32. for(let example of data){
  33. row.push(example);
  34. if(row.length >= 6){
  35. rows.push(row);
  36. row = [];
  37. }
  38. };
  39. rows.push(row);
  40. for(const row of rows){
  41. let thumbnails = "";
  42. let labels = "";
  43. for(let example of row){
  44. let url = example.url.startsWith("http") ?
  45. example.url :
  46. `http://potree.org/potree/examples/${example.url}`;
  47. thumbnails += `<td>
  48. <a href="${url}" target="_blank">
  49. <img src="examples/${example.thumb}" width="100%" />
  50. </a>
  51. </td>`;
  52. labels += `<th>${example.label}</th>`;
  53. }
  54. code += `<tr>
  55. ${thumbnails}
  56. </tr>
  57. <tr>
  58. ${labels}
  59. </tr>`;
  60. }
  61. return code;
  62. }
  63. async function createGithubPage(){
  64. const content = await fsp.readFile("./examples/page.json", 'utf8');
  65. const settings = JSON5.parse(content);
  66. const files = await fsp.readdir("./examples");
  67. let unhandledCode = ``;
  68. let exampleCode = toCode(files, settings.examples);
  69. let vrCode = toCode(files, settings.VR);
  70. let showcaseCode = toCode(files, settings.showcase);
  71. let thirdpartyCode = toCode(files, settings.thirdparty);
  72. let page = `
  73. <h1>Examples</h1>
  74. <table>
  75. ${exampleCode}
  76. </table>
  77. <h1>VR</h1>
  78. <table>
  79. ${vrCode}
  80. </table>
  81. <h1>Showcase</h1>
  82. <table>
  83. ${showcaseCode}
  84. </table>
  85. <h1>Third Party Showcase</h1>
  86. <table>
  87. ${thirdpartyCode}
  88. </table>`;
  89. fs.writeFile(`examples/github.html`, page, (err) => {
  90. if(err){
  91. console.log(err);
  92. }else{
  93. console.log(`created examples/github.html`);
  94. }
  95. });
  96. }
  97. exports.createGithubPage = createGithubPage;