item.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. template() {
  3. artifacts=$(echo "$1" | head -n1 | cut -d ';' -f1)
  4. toy=$(echo "$1" | head -n1 | cut -d ';' -f2)
  5. item=$(echo "$1" | head -n1 | cut -d ';' -f3)
  6. status=$(echo "$1" | head -n1 | cut -d ';' -f4)
  7. content1=$(echo "$1" | head -n1 | cut -d ';' -f5-)
  8. content2=$(echo "$1" | tail -n+2)
  9. content=$(printf '%s\n%s\n' "$content1" "$content2" | sed -E 's/ ([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{9}\+[0-9]{2}:[0-9]{2})/\n\1/g')
  10. cat <<EOF
  11. <!DOCTYPE html>
  12. <html>
  13. <head>
  14. <meta charset="UTF-8">
  15. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  16. EOF
  17. printf '\t\t<title>toymaker::%s/%s</title>\n' "$toy" "$item"
  18. cat <<EOF
  19. <style>
  20. * {
  21. box-sizing: border-box;
  22. }
  23. a {
  24. color: #00afff;
  25. }
  26. a:hover {
  27. background-color: #db9d3b;
  28. color: #000000;
  29. }
  30. </style>
  31. </head>
  32. <body style="background-color: #292929; color: #fafafa;">
  33. <header style="font-size: 1.25rem; padding-top: .3125rem; padding-bottom: .3125rem;">
  34. <a href="/toys/" style="font-family: monospace; text-decoration: none;">toymaker</a>
  35. </header>
  36. <main style="margin-left: 1rem; margin-top: 2rem;">
  37. EOF
  38. printf '\t\t\t<h1><a href="/toys/%s">%s</a>/%s</h1>\n' "$toy" "$toy" "$item"
  39. if [ "$status" = '0' ]
  40. then
  41. printf '\t\t\t<h2 style="color: #5af78e;">OK</h2>\n'
  42. elif [ "$status" = 'r' ]
  43. then
  44. printf '\t\t\t<h2>Running</h2>\n'
  45. else
  46. printf '\t\t\t<h2 style="color: #ff5c57;">Error</h2>\n'
  47. fi
  48. if [ -n "$artifacts" ]
  49. then
  50. printf '\t\t\t<details>\n'
  51. printf '\t\t\t\t<summary style="cursor: pointer;">artifacts</summary>\n'
  52. printf '\t\t\t\t<ul>\n'
  53. for artifact in $artifacts
  54. do
  55. printf '\t\t\t\t\t<li><a href="/toys/%s/%s/%s">%s</a></li>\n' "$toy" "$item" "$artifact" "$artifact"
  56. done
  57. printf '\t\t\t</details>'
  58. fi
  59. printf '\t\t\t<code><pre style="border: 1px #aaa solid; padding: 1rem; overflow: scroll; color: #cdb360;">\n'
  60. printf '%s' "$content"
  61. printf '\t\t\t</pre></code>\n'
  62. cat <<EOF
  63. </main>
  64. </body>
  65. </html>
  66. EOF
  67. }