Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

133 rindas
2.5 KiB

  1. #!/usr/bin/node
  2. const fs = require('fs');
  3. var DIR = process.argv[2];
  4. var TITLE = process.argv[3] || "Gallery";
  5. if(!DIR || !TITLE) {
  6. console.log(`### ERROR! No directory and/or title provided!`);
  7. console.log(`Usage: node gallery.js {directory} {title}`);
  8. process.exit(1);
  9. }
  10. outHtml = `
  11. <head><title>${TITLE}</title></head>
  12. <style>
  13. body {
  14. font-family: 'Segoe UI', Arial;
  15. background-color: #aaa;
  16. padding: 0;
  17. margin: 0;
  18. }
  19. .bg0 {
  20. background-image: url("../_tools/background.png")
  21. }
  22. .bg1 {
  23. background-color: #333;
  24. }
  25. .bg2 {
  26. background-color: #fff;
  27. }
  28. .imgbox img {
  29. width: 10.5rem;
  30. height: 10.5rem;
  31. object-fit: contain;
  32. cursor: pointer;
  33. }
  34. .imgbox {
  35. margin: 0.6rem;
  36. padding: 0.5rem;
  37. text-align: center;
  38. width: 12rem;
  39. height: 12rem;
  40. background-color: #e0e0e0;
  41. }
  42. h1 {
  43. font-size: 2.6rem;
  44. }
  45. .find, .find input {
  46. font-size: 1.5rem;
  47. }
  48. .top {
  49. position: -webkit-sticky;
  50. position: sticky;
  51. top: 0;
  52. background-color: #aaa;
  53. padding: 1rem;
  54. padding-top: 0;
  55. box-shadow: 0px 5px 18px 3px rgba(0,0,0,0.59);
  56. }
  57. .top button {
  58. float: right;
  59. position: relative;
  60. top: -2rem;
  61. font-size: 1.5rem;
  62. }
  63. .label {
  64. height: 2.5em;
  65. line-height: 1em;
  66. overflow: hidden;
  67. font-size: 0.9rem;
  68. }
  69. .grid {
  70. display: flex;
  71. flex-wrap: wrap;
  72. width: 100%;
  73. }
  74. </style>
  75. <body>
  76. <div class="top">
  77. <h1>${TITLE}</h1>
  78. <span class="find">Finder: <input onkeyup="search()" id="finder"><br></span>
  79. <button onclick="toggleBg()">Change Background</button>
  80. </div>
  81. <div class="grid">
  82. `
  83. var files = fs.readdirSync(DIR);
  84. for(let f of files) {
  85. if(!f.endsWith(".svg")) continue;
  86. outHtml += `<div id="${f}" class="imgbox"><a href="${f}" download><img src="${f}" class="bg0"/></a><div class="label">${f}</div></div>\n`
  87. }
  88. outHtml += `
  89. </div>
  90. <script>
  91. var bg = 0;
  92. function toggleBg() {
  93. bg++
  94. if(bg > 2) bg = 0;
  95. for(let img of document.getElementsByTagName("img")) {
  96. img.className = \`bg\${bg}\`;
  97. }
  98. }
  99. function search() {
  100. let q = document.getElementById('finder').value.trim().toLowerCase()
  101. if(q.length <= 0) {
  102. for(let imgbox of document.getElementsByClassName("imgbox")) {
  103. imgbox.style.display = "inline-block"
  104. }
  105. }
  106. for(let imgbox of document.getElementsByClassName("imgbox")) {
  107. imgbox.style.display = "inline-block"
  108. if(!imgbox.id.includes(q)) {
  109. imgbox.style.display = "none"
  110. }
  111. }
  112. }
  113. function download(f) {
  114. let a = document.createElement('a')
  115. a.href = f
  116. a.download = f
  117. console.log(a)
  118. a.click()
  119. }
  120. </script>
  121. </body></html>`
  122. console.log(`### Generating gallery index.html for ${DIR}`);
  123. fs.writeFileSync(DIR + '/index.html', outHtml);