Giter VIP home page Giter VIP logo

hexo_resize_image.js's Introduction

hexo_resize_image.js

在使用 Hexo 的过程中发现 Markdown 的原生语法貌似没办法设置图片的大小。

在网上搜索了一下,貌似比较好的做法是:

<img src="/image/test.jpg" width="50%" height="50%">

不过我还是想用 Markdown 的原生语法,于是用我抠脚的 JS 写了一个,源码附在底端。

语法

扩展了 Markdown 的插图语法如下:

  1. 可指定像素

    方法是在 URL 后面添加 ?<width>x<height>

    ![指定像素](/image/test.jpg?200x200)

    可以只指定一个参数,图片会等比例缩放。

    ![仅指定width](/image/test.jpg?200x)
    ![仅指定height](/image/test.jpg?x200)
  2. 可指定缩放比例

    方法是在 URL 后面添加 ?<scale>,等比例缩放图片大小至 %。

    ![指定比例](/image/test.jpg?40)

添加到页面中

在模板中为页面添加 js 脚本。

我使用的是 huno 主题,在 theme/huno/layout/layout.ejs</body> 前添加了如下语句:

<script src="<%- config.root %>js/hexo_resize_image.js"></script>

hexo_resize_image.js's People

Contributors

bobcn avatar

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.