diff --git a/assets/audio.scss b/assets/audio.scss new file mode 100644 index 0000000..2d1123a --- /dev/null +++ b/assets/audio.scss @@ -0,0 +1,76 @@ +.audio-player { + display: -webkit-flex; + display: flex; + align-items: center; + width: 300px; + background-color: #ededed; + border-radius: 20px; + margin-bottom: 20px; +} + + +.left_part { + padding-left: 20px; + padding-top: 20px; + padding-bottom: 20px; + width: 240px; +} + +.music_title { + font-size: 16px; + text-align: center; + margin-bottom: 10px; + color: #3f3f3f; +} + +.music_duration { + color: #91a0ae; + display: flex; + justify-content: space-between; +} + +.music_progress { + background-color: #c6bfbf; + border-radius: 5px; + height: 6px; + position: relative; + cursor: pointer; +} + +.progress_inplay { + background-color: #5781b2; + border-radius: 5px; + height: 100%; + width: 0%; + transition: all 0.2s linear; +} + + +.right_part { + margin-left: 30px; + width: 80px; +} + + +.player_controls { + display: flex; + justify-content: center; + align-items: center; + } + +.fas { + color: #5781b2; + cursor: pointer; + margin-right: 25px; + user-select: none; + transition: all 0.3s ease-in; + } + +.fas:hover { + filter: brightness(80%); + } + +.play-button { + font-size: 36px; +} + diff --git a/layouts/partials/head.html b/layouts/partials/head.html index cb33a4a..215bb25 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -35,6 +35,8 @@ {{ $style := resources.Get "style-refractored.scss" | resources.ToCSS | resources.Minify | resources.Fingerprint }} +{{ $style_2 := resources.Get "audio.scss" | resources.ToCSS | resources.Minify | resources.Fingerprint }} + @@ -69,5 +71,8 @@ {{ end }} +{{/* audio file play */}} + + {{ .Site.Params.title }} diff --git a/layouts/partials/link-block.html b/layouts/partials/link-block.html index f16c601..8179222 100644 --- a/layouts/partials/link-block.html +++ b/layouts/partials/link-block.html @@ -3,6 +3,7 @@ {{ $resource_type := "link" }} {{ $logo_file := "default_link_logo.png" }} +{{ $index := .index | safeJS }} {{/* 1.1 Wechat articles */}} {{ if eq 1 (len (findRE `(https?://)?mp\.weixin\.qq\.com([-a-zA-Z0-9()@:%\+.~#?&/=_]*)` .a)) }} @@ -49,6 +50,14 @@ {{ $bilibili_video_url = replaceRE `` "$1" .a }} {{ end }} + +{{/* 2.3 audio/music support */}} +{{ if eq 1 (len (findRE `.*\.(mp3|MP3|flac|FLAC|wav|WAV)` .a)) }} + {{ $resource_type = "audio_file" }} + {{ $audio_file_url := .a }} +{{ end }} + + {{/* BEGIN generate output */}} {{/* PART 1 default link */}} {{ if eq "link" $resource_type }} @@ -83,4 +92,48 @@
-{{ end }} \ No newline at end of file +{{ end }} + + +{{/* audio/music support */}} +{{ if eq "audio_file" $resource_type }} + +
+
+
{{ .word }}
+
+ 00 : 00 + 00 : 00 +
+
+
+
+
+ +
+
+ +
+
+
+ + + +{{ end }} + + diff --git a/layouts/partials/row.html b/layouts/partials/row.html index 8a58618..ebc748b 100644 --- a/layouts/partials/row.html +++ b/layouts/partials/row.html @@ -131,7 +131,7 @@ {{ with $page.Params.link }} {{ partial "link-block.html" (dict "logo" $link_logo "a" $link_link "word" $link_text "baseurl" - $page.Site.BaseURL)}} + $page.Site.BaseURL "index" $index) }} {{ end }} {{/* Note info shown below the main content */}} diff --git a/static/scripts/audio-play.js b/static/scripts/audio-play.js new file mode 100644 index 0000000..4140d79 --- /dev/null +++ b/static/scripts/audio-play.js @@ -0,0 +1,49 @@ +let currentPlayBtn = null; +let currentPlaySong = null; + +function togglePlay(nextPlaySong, nextBtn) { + if (currentPlaySong == nextPlaySong) { + // pause + currentPlayBtn.classList.replace("fa-pause", "fa-play"); + currentPlaySong.pause(); + currentPlayBtn = null; + currentPlaySong = null; + return; + } + + if (currentPlaySong != null) { + // currently there is no music playing. + currentPlaySong.pause(); + currentPlayBtn.classList.replace("fa-pause", "fa-play"); + } + + // currenty there is music playing. + currentPlayBtn = nextBtn + currentPlaySong = nextPlaySong + nextBtn.classList.replace("fa-play", "fa-pause"); + nextPlaySong.play(); +} + + +function setProgressBar(e, playerProgressEl, song) { + const width = playerProgressEl.clientWidth; + const xValue = e.offsetX; + console.log(width); + console.log(xValue); + song.currentTime = (xValue / width) * song.duration; +} + +function updateProgressBar(progressEl, durationEl, currentTimeEl, song) { + const { duration, currentTime } = song; + const ProgressPercent = (currentTime / duration) * 100; + progressEl.style.width = `${ProgressPercent}%`; + const formattime = (timeRanges) => + String(Math.floor(timeRanges)).padStart(2, "0"); + durationEl.textContent = `${formattime(duration / 60)} : ${formattime( + duration % 60, + )}`; + currentTimeEl.textContent = `${formattime(currentTime / 60)} : ${formattime( + currentTime % 60, + )}`; +} +