1
Fork 0

Add ListenBrainz currently playing song.

This commit is contained in:
Bauke 2021-11-26 19:24:42 +01:00
parent 72fd3351b3
commit 4849fb9ebc
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
7 changed files with 1408 additions and 50 deletions

View File

@ -5,13 +5,14 @@
"scripts": { "scripts": {
"deploy": "cargo run --release -q && yarn deploy:netlify", "deploy": "cargo run --release -q && yarn deploy:netlify",
"deploy:netlify": "netlify deploy --prod --dir 'public/' -s bauke.xyz", "deploy:netlify": "netlify deploy --prod --dir 'public/' -s bauke.xyz",
"test": "stylelint 'source/**/*.scss'" "test": "xo && stylelint 'source/**/*.scss'"
}, },
"devDependencies": { "devDependencies": {
"netlify-cli": "^8.0.1", "netlify-cli": "^8.0.1",
"stylelint": "^14.1.0", "stylelint": "^14.1.0",
"stylelint-config-xo-scss": "^0.14.0", "stylelint-config-xo-scss": "^0.14.0",
"stylelint-config-xo-space": "^0.15.1" "stylelint-config-xo-space": "^0.15.1",
"xo": "^0.47.0"
}, },
"stylelint": { "stylelint": {
"extends": [ "extends": [
@ -28,5 +29,16 @@
"scss/at-import-partial-extension": null, "scss/at-import-partial-extension": null,
"scss/at-rule-no-unknown": null "scss/at-rule-no-unknown": null
} }
},
"xo": {
"pretty": true,
"globals": [
"document",
"window"
],
"rules": {
"capitalized-comments": "off"
},
"space": true
} }
} }

18
source/js/listenbrainz.js Normal file
View File

@ -0,0 +1,18 @@
window.addEventListener('DOMContentLoaded', async () => {
const result = await window.fetch('https://api.listenbrainz.org/1/user/BaukeXYZ/playing-now');
if (!result.ok) {
console.warn(result.status);
return;
}
const data = await result.json();
const listen = data.payload.listens[0];
const listenHtml = `<div class="divider"></div><div class="listenbrainz">
<a href="https://listenbrainz.org/user/BaukeXYZ/" target="_blank">
<img src="https://listenbrainz.org/static/img/logo_big.svg">
${listen.track_metadata.artist_name} - ${listen.track_metadata.track_name}
</a>
</div>`;
document.querySelector('.page-main').insertAdjacentHTML('beforeend', listenHtml);
});

View File

@ -92,7 +92,10 @@ fn main() -> color_eyre::Result<()> {
fs::copy(source, destination)?; fs::copy(source, destination)?;
} }
let dirs_to_copy = vec![(build_dir.join("userstyles"), public_dir)]; let dirs_to_copy = vec![
(source_dir.join("js"), &public_dir),
(build_dir.join("userstyles"), &public_dir),
];
for (source, destination) in dirs_to_copy { for (source, destination) in dirs_to_copy {
Command::new("cp") Command::new("cp")

View File

@ -0,0 +1,18 @@
.listenbrainz a {
align-items: center;
border: 2px solid #fff;
display: flex;
margin-top: 1rem;
padding: 1rem;
&:hover {
background-color: #fff;
border-color: #fff;
color: #000;
}
img {
height: 3rem;
margin-right: 1rem;
}
}

View File

@ -24,9 +24,16 @@ button {
font-family: monospace; font-family: monospace;
} }
.divider {
border-top: 2px solid #fff;
margin-bottom: 1rem;
margin-top: 1rem;
}
@import 'components/errors'; @import 'components/errors';
@import 'components/page-footer'; @import 'components/page-footer';
@import 'components/page-header'; @import 'components/page-header';
@import 'components/page-main'; @import 'components/page-main';
@import 'components/listenbrainz';
@import 'components/userstyles'; @import 'components/userstyles';

View File

@ -24,4 +24,6 @@
</a> </a>
</div> </div>
</main> </main>
<script src="/js/listenbrainz.js"></script>
{% endblock %} {% endblock %}

1392
yarn.lock

File diff suppressed because it is too large Load Diff