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

metalsmith-hammer

v0.2.0

Published

Command-line goodness for metalsmith users

Downloads

7

Readme

metalsmith-hammer

Metalsmith is an extremely simple, pluggable static site generator. It lets you chain plugins together to create complex static site builders (and more).

But every smith needs a hammer. A command-line centric workflow is pretty snappy and awesome, but it can get bothersome to keep opening, creating and dropping markdown and other documents all over your project tree. That's what this package is for. When in doubt, use a hammer.

example

This project is in early stages of development. For now, only the core feature of editing metalsmith files with your favorite editor has been implemented. Over time I will add more features and further polish the metalsmithing command-line experience.

Feel free to request features or submit pull requests! Honestly, I've only just begun using metalsmith and felt the need to write this to make my own experience smoother. Chances are you know better than I do what could be useful additions to this. By the way, I based this on my other, similar plugin for hexo so take a look there if you're also a hexo user.

Installation

npm install -g metalsmith-hammer

This is a global package and you only need to install it once. It's not quite a metalsmith plugin so don't install it locally or include it in your static site's package.json or metalsmith.json.

Read this or install nvm if you find you need sudo.

tl;dr

Running hammer edit anywhere within a directory associated with a metalsmith static site generator will give you a list of all markdown files in the ./src directory. Select one and it will open in your $EDITOR. If you don't have this environment variable or if you run hammer with -g/--gui, the file will open in the associated GUI program instead (ie, Atom or Sublime or whatever).

Renamed your src directory? Drop a .hammer.json file in your project root dir and put this in it:

{
  "source": "your_source_directory",
}

Not writing in markdown? Add "defaultType": "your_favorite_file_extension" to .hammer.json or use the type option on the command-line.

Filter your hammer queries with regular expressions like this: hammer edit search term. Now only articles will pop up in the menu that contain /search/ and /term/. Only care about files in your posts collection? Just add -d posts to your query (--dir or --directory works too).

hammer edit

The core and for now only feature of hammer is edit. This is what happens when you run hammer edit somewhere in your file system:

  • hammer identifies the root directory of the project and checks whether it includes metalsmith
  • If it exists, a project-specific .hammer.json overwrites the default configuration settings (see below)
  • All files that match both your query and the configuration settings are displayed in a menu and you choose the one you want to edit
  • The selected file opens in your $EDITOR or associated GUI program

Default settings and .hammer.json

These are the default settings:

{
  "source": "src",
  "sourceDirs": [],
  "defaultType": "md"
}

Overwrite individual (or all) options on a project-per-project basis by including a .hammer.json file.

  • source: The main directory you want to edit files in
  • sourceDirs: An array of extra (top-level) directories you want to edit files in. For example, you may want to add layouts or partials here if you want to use hammer to edit the files in those directories.
  • defaultType: The default filetype to look for

edit options

As noted earlier, hammer edit will present you with a list of all files located somewhere within the source or sourceDirs dirs that match the defaultType.

Fine-tune your query by using any or all of the following:

  • regular expressions: every word that isn't an option will be treated as a regular expression to filter the files on. Right now, just the filenames are taken into consideration
  • -d/--dir/--directory: you probably have subfolders in your source director{y,ies}. Select only a specific subdirectory by using this option
  • -t/--type: specify a file extension. In effect this overwrites your defaultType for a single query

Examples:

hammer edit
hammer edit cool post
hammer edit -d articles
hammer edit -t html
hammer edit app -d scripts -t js

Todo

  • implement more commands - rename, delete, new
  • allow searching and filtering on metadata & file content
  • tests