Mobile-responsive personal website, generated using Hugo. https://kevin-mok.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  1. const log = console.log
  2. const headerKeys = {
  3. "status": "Status",
  4. "url": "URL",
  5. "description": "Description",
  6. "repo": "Repository"
  7. }
  8. const keyOrder = ["status", "url", "description", "repo"]
  9. function generateTableHead(table) {
  10. let thead = table.createTHead();
  11. let row = thead.insertRow();
  12. keyOrder.forEach(key => {
  13. let th = document.createElement("th");
  14. th.textContent = headerKeys[key];
  15. row.appendChild(th);
  16. })
  17. }
  18. function generateTable(table, data) {
  19. data.forEach(elem => {
  20. let row = table.insertRow();
  21. keyOrder.forEach(key => {
  22. const cell = row.insertCell();
  23. cell.className = key;
  24. const aElem = document.createElement('a')
  25. aElem.target = '_blank'
  26. switch (key) {
  27. case 'status':
  28. // cell.textContent = ((elem[key] == 'up') ? '🗸' : '✗')
  29. const statusIcon = document.createElement('img')
  30. statusIcon.src = '/img/server/' + ((elem[key] == 'up') ? 'check' : 'x') + '.svg'
  31. cell.appendChild(statusIcon)
  32. break
  33. case 'url':
  34. aElem.href = elem[key]
  35. aElem.textContent = elem['shortUrl']
  36. cell.appendChild(aElem)
  37. break
  38. case 'repo':
  39. aElem.href = elem['repoUrl']
  40. aElem.textContent = elem[key]
  41. cell.appendChild(aElem)
  42. break
  43. default:
  44. cell.textContent = elem[key]
  45. }
  46. })
  47. })
  48. }
  49. // fetch("http://localhost:1313/server-apps.json")
  50. fetch("/server-apps.json")
  51. .then(response => response.json())
  52. .then(json => {
  53. // console.log(json)
  54. let table = document.querySelector("table");
  55. generateTable(table, json);
  56. generateTableHead(table);
  57. });