Static site generator for making web mixtapes in 2020.
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.

111 lines
2.8 KiB

  1. // Code generated by "inline -o templates.go -p cdr mixtape.tmpl templates/parts.tmpl" -- DO NOT EDIT --
  2. package cdr
  3. import (
  4. "fmt"
  5. "io/ioutil"
  6. )
  7. func ReadAsset(file string, useLocal bool) ([]byte, error) {
  8. if useLocal {
  9. return ioutil.ReadFile(file)
  10. }
  11. if f, ok := files[file]; ok {
  12. return []byte(f), nil
  13. }
  14. return nil, fmt.Errorf("file doesn't exist.")
  15. }
  16. var files = map[string]string{
  17. "mixtape.tmpl": `{{define "mixtape"}}
  18. <html>
  19. <head>
  20. <title>Mixtape</title>
  21. <style type="text/css">
  22. body {
  23. font-size: 1.2em;
  24. margin: 1em;
  25. }
  26. #playlist {
  27. list-style: decimal-leading-zero;
  28. margin: 1em 0;
  29. }
  30. #playlist li {
  31. margin: 0.5em 0;
  32. }
  33. li.active a {
  34. font-weight: bold;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. {{template "full-player" .Tracks}}
  40. </body>
  41. </html>
  42. {{end}}`,
  43. "templates/parts.tmpl": `{{define "player"}}
  44. {{with $x := index . 0}}
  45. <audio id="player" preload="auto" tabindex="0" controls>
  46. <source src="{{$x.Filename}}">
  47. </audio>
  48. {{end}}
  49. {{end}}
  50. {{define "playlist"}}
  51. <ol id="playlist">
  52. {{range $i, $el := .}}
  53. <li{{if eq $i 0}} class="active"{{end}}>
  54. <a href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
  55. </li>
  56. {{end}}
  57. </ol>
  58. {{end}}
  59. {{define "full-player"}}
  60. {{template "player" .}}
  61. {{template "playlist" .}}
  62. {{template "playlist-js"}}
  63. {{end}}
  64. {{define "playlist-js"}}
  65. <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  66. <script type="text/javascript">
  67. $(document).ready(function() {
  68. init();
  69. function init() {
  70. var current = 0;
  71. var $audio = $('#player');
  72. var $playlist = $('#playlist');
  73. var $tracks = $playlist.find('li a');
  74. var len = $tracks.length - 1;
  75. $playlist.on('click', 'a', function (e) {
  76. e.preventDefault();
  77. link = $(this);
  78. current = link.parent().index();
  79. run(link, $audio[0]);
  80. });
  81. $audio[0].addEventListener('ended', function (e) {
  82. current++;
  83. if (current == len) {
  84. current = 0;
  85. link = $playlist.find('a')[0];
  86. } else {
  87. link = $playlist.find('a')[current];
  88. }
  89. run($(link), $audio[0]);
  90. });
  91. }
  92. function run($link, $player) {
  93. $player.src = $link.attr('href');
  94. par = $link.parent();
  95. par.addClass('active').siblings().removeClass('active');
  96. $player.load();
  97. $player.play();
  98. }
  99. });
  100. </script>
  101. {{end}}`,
  102. }