博客中插入图片音乐视频

  1. 本地引用
    1. 下载插件
    2. 更改配置文件
  2. 下载的插件js可能存在问题
  3. 插入音乐
    1. 音乐实验
  • 插入视频
    1. 插入视频测试
  • 本地引用

    下载插件

    npm install hexo-asset-image –save

    更改配置文件

    插入本地图片需要修改主题_config.yml配置文件post_asset_folder项为true

    这里我更改的是hexo目录下的配置文件
    更改配置截图

    下载的插件js可能存在问题

    用下面的代码替换 hexo-asset-image目录下的js文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    'use strict';
    var cheerio = require('cheerio');

    // http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string
    function getPosition(str, m, i) {
    return str.split(m, i).join(m).length;
    }

    var version = String(hexo.version).split('.');
    hexo.extend.filter.register('after_post_render', function(data){
    var config = hexo.config;
    if(config.post_asset_folder){
    var link = data.permalink;
    if(version.length > 0 && Number(version[0]) == 3)
    var beginPos = getPosition(link, '/', 1) + 1;
    else
    var beginPos = getPosition(link, '/', 3) + 1;
    // In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html".
    var endPos = link.lastIndexOf('/') + 1;
    link = link.substring(beginPos, endPos);

    var toprocess = ['excerpt', 'more', 'content'];
    for(var i = 0; i < toprocess.length; i++){
    var key = toprocess[i];

    var $ = cheerio.load(data[key], {
    ignoreWhitespace: false,
    xmlMode: false,
    lowerCaseTags: false,
    decodeEntities: false
    });

    $('img').each(function(){
    if ($(this).attr('src')){
    // For windows style path, we replace '\' to '/'.
    var src = $(this).attr('src').replace('\\', '/');
    if(!/http[s]*.*|\/\/.*/.test(src) &&
    !/^\s*\//.test(src)) {
    // For "about" page, the first part of "src" can't be removed.
    // In addition, to support multi-level local directory.
    var linkArray = link.split('/').filter(function(elem){
    return elem != '';
    });
    var srcArray = src.split('/').filter(function(elem){
    return elem != '' && elem != '.';
    });
    if(srcArray.length > 1)
    srcArray.shift();
    src = srcArray.join('/');
    $(this).attr('src', config.root + link + src);
    console.info&&console.info("update link as:-->"+config.root + link + src);
    }
    }else{
    console.info&&console.info("no src attr, skipped...");
    console.info&&console.info($(this));
    }
    });
    data[key] = $.html();
    }
    }
    });

    插入音乐

    比如网易云音乐,找到喜欢的歌曲,点击分享按钮,把里面的代码复制下来,直接粘贴到博文中即可

    1
    2
    3
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 
    src="http://music.163.com/outchain/player?type=2&id=25706282&auto=0&height=66">
    </iframe>

    音乐实验

    插入视频

    1
    2
    3
    4
    5
    6
    <iframe 
    height=1000 width=1020
    src="http://player.youku.com/embed/XNjcyMDU4Njg0"
    //http://music.163.com/song?id=63612&userid=357443816
    frameborder=0 allowfullscreen>
    </iframe>

    插入视频测试


    转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 583614868@qq.com

    文章标题:博客中插入图片音乐视频

    文章字数:566

    本文作者:钟帅豪

    发布时间:2019-11-07, 08:45:43

    最后更新:2019-11-07, 17:28:42

    原始链接:http://jhshz520.github.io/2019/11/07/博客中插入图片音乐视频/

    版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

    目录
    ×

    喜欢就点赞,疼爱就打赏