Giter Site home page Giter Site logo

Comments (5)

blackier avatar blackier commented on June 12, 2024

然后我再测试发现,文件里有空格,也是有问题。需要改下最后的匹配格式,但如果文件名本身就有%20,那么也会问题。但这个的概率感觉比空格的概率低。

    data.content = data.content.replace(regExp, function(matchStr, group1, group2, group3){
        var imgname = group3.replace("%20", " ");
        return `{% asset_img "${imgname}" "${group1}" %}`;
       }, "g");

from hexo-asset-img.

yiyungent avatar yiyungent commented on June 12, 2024

收到,感谢你的贡献!最近比较忙(电脑都用不上),等下次有时间我再来更新下(好奇怪,我居然没收到这个issue通知),其实你可以直接pull request,然后我自己合并也行

from hexo-asset-img.

blackier avatar blackier commented on June 12, 2024

收到,感谢你的贡献!最近比较忙(电脑都用不上),等下次有时间我再来更新下(好奇怪,我居然没收到这个issue通知),其实你可以直接pull request,然后我自己合并也行

呃主要是我不是搞js的,代码不多大致看得懂流程才学了下语法,就改了下,pr就不提了,等你后面修改吧。

from hexo-asset-img.

tedcy avatar tedcy commented on June 12, 2024

文件名里面有特殊符号都会有问题
根据https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript的建议
文件名用escapeRegex处理一下就可以解决问题了

function escapeRegex(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}

from hexo-asset-img.

yiyungent avatar yiyungent commented on June 12, 2024

然后我再测试发现,文件里有空格,也是有问题。需要改下最后的匹配格式,但如果文件名本身就有%20,那么也会问题。但这个的概率感觉比空格的概率低。

    data.content = data.content.replace(regExp, function(matchStr, group1, group2, group3){
        var imgname = group3.replace("%20", " ");
        return `{% asset_img "${imgname}" "${group1}" %}`;
       }, "g");

今天想起来写了个在线测试 demo (懒癌晚期),这个写法不行啊

https://replit.com/@yiyungent/hexo-asset-img-test#index.js

image

from hexo-asset-img.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.