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

hexo-custom-layout

v1.1.1

Published

Load custom layouts and render partial template

Downloads

4

Readme

Hexo custom layout

CI npm version

Changelog | NPM registry

This Hexo plugin allows user to:

  • Load custom layouts without modifying theme files
  • Apply custom layouts from a relative path or from post asset folder
  • Use tags to insert another file into posts or pages
    • Markdown, HTML, etc.
  • Insert templates into posts or pages
    • Nunjucks, EJS, etc. Same as layouts
    • Can pass arguments when referencing
  • Generate sub pages as standalone pages in post asset folders

Quick Start

Global custom layout

The plugin provides a config key layout_dir for setting the name of directory that stores global layouts. The default value is layout.

For example, your website has a video collection and you want to create a layout to be applied to all video pages, so that you only need to write the video file address in the front matter, and the template will build the video page.

  • Create layout folder in your website root directory (same level as source)
  • Write a template video.ejs according to guides on hexo theme
  • Put video.ejs in layout
  • Add layout: video in the front matter of your video pages

Portable custom layout

You can also put layouts together with your pages, in source folder. Name those in the format of <name>.layout.ejs or <name>.layout.njk, and write layout_from: example in the front matter of the page you want to apply to.

source/_post/example.layout.njk

<body>
  <h1>{{ page.title }}</h1>
  <div>Behold! {{ page.content }}</div>
</body>

source/_post/main.html

---
title: Welcome
layout_from: example
---
The great and powerful Triksyie!

Rendered result

<body>
  <h1>Welcome</h1>
  <div>Behold! The great and powerful Triksyie!</div>
</body>

Include snippet file

Use the nunjucks tag snippet to include a snippet file. The snippet file must be named as <name>.snippet.html, or <name>.snippet.md, etc.

source/_post/avatar.snippet.html

<div class='avatar'>
  <img src='/images/avatar.png'></img>
</div>

source/_post/main.html

<body>
  This is my avatar:
  {% snippet avatar.html %}
</body>

Note that you must remove the .snippet part in the filename when referencing.

Rendered result

<body>
  This is my avatar:
  <div class='avatar'>
    <img src='/images/avatar.png'></img>
  </div>
</body>

Besides that, the second parameter of the tag can be chosen from from, asset, and global. They corresponds to relative path, path in post asset folder, and global path. In the example above, {% snippet bibliography.md asset %} will reference source/_post/main/bibliography.md.

Inserting templates works similarly. See relevant test files for example usage

Asset pages

Put pages in post asset folder and name them as <name>.page.<ext> to render them as standalone pages. See tests for examples.

See under test for more examples.