Static site generator for making web mixtapes in 2020.

templates.go 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. <meta charset="UTF-8" />
  22. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  23. <style type="text/css">
  24. body {
  25. font-size: 1.2em;
  26. margin: 1em;
  27. }
  28. #playlist {
  29. list-style: decimal-leading-zero;
  30. margin: 1em 0;
  31. }
  32. #playlist li {
  33. margin: 0.5em 0;
  34. }
  35. li p {
  36. display: none;
  37. font-style: italic;
  38. }
  39. li.active a {
  40. font-weight: bold;
  41. }
  42. li.active p {
  43. display: block;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. {{template "full-player" .Tracks}}
  49. </body>
  50. </html>
  51. {{end}}
  52. {{define "track-info"}}
  53. {{if eq .Num 1}}
  54. <p>[Here I might introduce this mix.]</p>
  55. <p>[Some notes about track 1.]</p>
  56. {{else if eq .Num 2}}
  57. <p>[Some notes about track 2.]</p>
  58. {{else if eq .Num 5}}
  59. <p>[Some notes about track 5.]</p>
  60. {{end}}
  61. {{end}}`,
  62. "templates/parts.tmpl": `{{define "player"}}
  63. {{with $x := index . 0}}
  64. <audio id="player" preload="auto" tabindex="0" controls>
  65. <source src="{{$x.Filename}}">
  66. </audio>
  67. {{end}}
  68. {{end}}
  69. {{define "playlist"}}
  70. <ol id="playlist">
  71. {{range $i, $el := .}}
  72. <li{{if eq $i 0}} class="active"{{end}}>
  73. <a class="track" href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
  74. {{template "track-info" $el}}
  75. </li>
  76. {{end}}
  77. </ol>
  78. {{end}}
  79. {{define "track-info"}}{{end}}
  80. {{define "full-player"}}
  81. {{template "player" .}}
  82. {{template "playlist" .}}
  83. {{template "playlist-js"}}
  84. {{end}}
  85. {{define "playlist-js"}}
  86. <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  87. <script type="text/javascript">
  88. $(document).ready(function() {
  89. var current = 0;
  90. var $audio = $('#player');
  91. var $playlist = $('#playlist');
  92. var $tracks = $playlist.find('li a.track');
  93. var len = $tracks.length;
  94. $playlist.on('click', 'a.track', function (e) {
  95. e.preventDefault();
  96. link = $(this);
  97. current = link.parent().index();
  98. play(link, $audio[0]);
  99. });
  100. $audio[0].addEventListener('ended', function (e) {
  101. playNext();
  102. });
  103. $('a#next').on('click', function (e) {
  104. e.preventDefault();
  105. playNext();
  106. });
  107. $('a#prev').on('click', function (e) {
  108. e.preventDefault();
  109. playPrev();
  110. });
  111. function playPrev() {
  112. current--;
  113. if (current <= 0) {
  114. current = len - 1;
  115. }
  116. link = $playlist.find('a.track')[current];
  117. play($(link), $audio[0]);
  118. }
  119. function playNext() {
  120. current++;
  121. if (current == len) {
  122. current = 0;
  123. }
  124. link = $playlist.find('a.track')[current];
  125. play($(link), $audio[0]);
  126. }
  127. function play($link, $player) {
  128. $player.src = $link.attr('href');
  129. par = $link.parent();
  130. par.addClass('active').siblings().removeClass('active');
  131. $player.load();
  132. $player.play();
  133. }
  134. });
  135. </script>
  136. {{end}}`,
  137. }