npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kur4ge/hexo-asset-path

v1.0.1

Published

A hexo plugin for making inserting assets to post and integrating with cdn easier.

Downloads

9

Readme

hexo-asset-path

npm version

In hexo, the images inserted by markdown syntax are often not points to the right place, due to relative path. We can use absolute path to work around this issue. But inserting the post permalink or asset folder every time is very annoying. Also, sometimes we don't like to store that much data on github, we like to move all the images to another CDN. It could be really painful, if you need to update every posts you wrote!

This plugin is written to deal with all these issues. It is trying to make inserting assets to post and integrating with CDN a lot more easier.

Installation

$ npm install hexo-asset-path --save

Usage

Setting up the configuration in _config.ymal

asset_path:
  enable: true

  # Asset folder, used when post asset folder is not enabled.
  # For example, the following asset folder configuration will make hexo to use "/r12f-assets/post-assets/2017-01-16-Hello-World" as the base URL in one of my post.
  asset_folder: /r12f-assets/post_assets/<% print(post_created.format('YYYY-MM-DD')) %>-<%= post_slug %>

  asset_prefix: ..

  # CDN settings, and CDN folder will always be considered to have its own domain and start from the root.
  enable_cdn: true
  cdn_folder: r12f-cdn.azureedge.net/r12f-assets/post_assets/<% print(post_created.format('YYYY-MM-DD')) %>-<%= post_slug %>
  cdn_use_https: false

  # Selectors and attribute names for getting the elements to update.
  selectors:
    img[src]: 'src'

Variables you can use in the asset folder and cdn folder:

  • post_title
  • post_slug
  • post_created
  • post_created_date
  • post_created_time

The variables are supported by underscore template, so you can even execute arbitrary JavaScript code with <% %>. For example, <% print(post_created.format('YYYY-MM-DD') %> will give you 2017-01-01, if today is that day.

Inserting assets

Just use the markdown syntax to insert your images, with the relative path (to the post asset folder if enabled, otherwise to your asset folder specified in hexo-asset-path configuration).

![your image](path/to/image.png)

Asset path in different modes

As we know, we can enable post asset folder in hexo, and hexo can create a local server to preview your blog, and you might like to enable CDN when you generate the real site. The asset path for showing your assets properly in these different modes are actually different. And the following table shows how we generate the asset path:

| | Local server | Real site | | -------------------------- | -------------------------------------------- | -------------------------------------------------------------------------- | | Post asset folder enabled | /PostPermalinkPathName/AssetPrefix/AssetPath | (CDN enabled ? //CDNFolder : )/PostPermalinkPathName/AssetPrefix/AssetPath | | Post asset folder disabled | /AssetFolder/AssetPrefix/AssetPath | (CDN enabled ? //CDNFolder : /AssetFolder)/AssetPrefix/AssetPath |

Debugging

The posts and links we updated is outputted to the hexo log. Just simply enable debug mode and logging in hexo, then you can see it.

hexo s --debug --log

License

BSD v3