Static site generator for making web mixtapes in 2020.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

154 linhas
3.9 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. <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 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');
  93. var len = $tracks.length;
  94. $playlist.on('click', 'a', function (e) {
  95. e.preventDefault();
  96. link = $(this);
  97. current = link.parent().index();
  98. console.log(current);
  99. play(link, $audio[0]);
  100. });
  101. $audio[0].addEventListener('ended', function (e) {
  102. playNext();
  103. });
  104. $('a#next').on('click', function (e) {
  105. e.preventDefault();
  106. playNext();
  107. });
  108. $('a#prev').on('click', function (e) {
  109. e.preventDefault();
  110. playPrev();
  111. });
  112. function playPrev() {
  113. current--;
  114. if (current <= 0) {
  115. current = len;
  116. link = $playlist.find('a')[0];
  117. } else {
  118. link = $playlist.find('a')[current];
  119. }
  120. play($(link), $audio[0]);
  121. }
  122. function playNext() {
  123. current++;
  124. if (current == len) {
  125. current = 0;
  126. link = $playlist.find('a')[0];
  127. } else {
  128. link = $playlist.find('a')[current];
  129. }
  130. play($(link), $audio[0]);
  131. }
  132. function play($link, $player) {
  133. $player.src = $link.attr('href');
  134. par = $link.parent();
  135. par.addClass('active').siblings().removeClass('active');
  136. $player.load();
  137. $player.play();
  138. }
  139. });
  140. </script>
  141. {{end}}`,
  142. }