Created
June 11, 2014 07:59
-
-
Save andrewboni/7b17c0341ce6fca6d379 to your computer and use it in GitHub Desktop.
A Hexo blog plugin for embedding Soundcloud songs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Soundcloud tag plugin | |
* | |
* Author: Andrew Boni | |
* | |
* Syntax: | |
* {% soundcloud <soundcloud song url> [type of player] %} | |
* | |
* Description: | |
* Embeds Soundcloud songs from a URL. Comes with an option to use the visual player or the default player. Possible | |
* options are 'visual', 'default', or simply leave it blank. | |
* | |
* Examples: | |
* {% soundcloud https://soundcloud.com/only-the-beat/3lau-electric-daisy-carnival-edc-new-york-2014 visual %} | |
* {% soundcloud https://soundcloud.com/only-the-beat/3lau-electric-daisy-carnival-edc-new-york-2014 default %} | |
* {% soundcloud https://soundcloud.com/only-the-beat/3lau-electric-daisy-carnival-edc-new-york-2014 %} | |
*/ | |
hexo.extend.tag.register("soundcloud", function(args) { | |
var options, songUrl, soundcloudUrl, type; | |
songUrl = args[0]; | |
type = args[1] || "default"; | |
soundcloudUrl = "https://w.soundcloud.com/player/?url=" + (encodeURIComponent(songUrl)); | |
if (type === "visual") { | |
options = "visual=true"; | |
} else if (type === "default") { | |
options = "color=ff5500&show_artwork=true"; | |
} else { | |
return "Error: Soundcloud player type option needs to be either <b>visual</b> or <b>default</b>."; | |
} | |
return "<iframe width='100%' height='160' scrolling='no' frameborder='no' src='" + soundcloudUrl + "&auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&" + options + "'></iframe>"; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment