Comments (2)
@xuexb 还是别编译动态获取了,直接要求用户在使用此模板是,如果需要使用img标签,必须定义宽高属性就行,hexojs
编译时只需读取 <img>
宽高属性值。
from hexo-theme-mip.
思路是在页面渲染后 after_render:html
,使用勾子把内容里的 <img>
替换为 <mip-img>
,代码是:
hexo.extend.filter.register('after_render:html',function (html) {
return html.replace(/<img([\S\s]+?)\/?>/ig,function (match,tag) {
return '<mip-img ${tag}></mip-img>'.replace('${tag}',tag.trim());
});
});
当然也可以做成自动抓取
- 如果是本地 - 直接获取图片信息,并设置宽高
- 如果是远程 - 根据链接生成
md5
小缀缀,远程下载图片到本地,获取宽高后使用小缀缀设置缓存,最后设置图片宽高
from hexo-theme-mip.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hexo-theme-mip.