Code Monkey home page Code Monkey logo

injectmeta's Introduction

A command line utility to inject meta tags into an html file or to remove code based on conditions.

Written because I could not find a command-line equivalent that could work with npm scripts instead of gulp.

This module injects meta tags between markers placed in an html file or removes code between markers. It can take a json file which will be transformed to strings and injected. It removes code between markers so you can for example remove livereload code which is not needed in a production environment. It can also inject the current git commit hash into the HTML as a comment so it is easily visible which commit is currently deployed.

This module was written in ES6 and requires node >= 4.0.0.

Usage

Place the markers in your html file to inject or remove code:

   <!DOCTYPE html>
   <html>
   <head>
     <title>Home</title>
     <meta name="viewport" content="width=device-width, initial-scale=1">

     <!-- inject:meta -->
     <meta name="devmeta" content="This meta will be replaced">
     <!-- endinject -->

   </head>
   <body>
        content
   </body>
   </html>
   <!-- inject:git-hash -->

The meta tags will be injected between the markers and the meta that are already there will be removed.

Options:

-h, --help             output usage information
-V, --version          output the version number
-i, --input <input>    Input file
-o, --output <output>  Output file (defaults to input when omitted)
-r, --remove <remove>  Remove condition
-H, --hash             Inject git hash of current commit

Examples

Given a meta.json file:

{
	"meta": [{
			"name": "testmeta",
			"content": "Example content"
		},{
			"name": "testmeta2",
			"content": "Example content 2"
		}]
}

injectmeta -i index.html -o dist/index.html -m meta.json

will result in the file dist/index.html:

   <!DOCTYPE html>
   <html>
   <head>
     <title>Home</title>

        <meta name="testmeta" content="Example content">
        <meta name="testmeta2" content="Example content 2">

   </head>
   <body>

   </body>
   </html>
   <!-- b64f022ae51d87a411c4608f403f3216ee028d03 -->

Notice that the code

     <!-- remove:production -->
     <script src="http://localhost:35729/livereload.js?snipver=1"></script>
     <!-- endremove -->

has been removed.

The comment

    <!-- inject:git-hash -->

has been replaced by the git hash of the current commit.

injectmeta's People

Contributors

viktorplohl avatar

Stargazers

Roman avatar

Watchers

 avatar

injectmeta's Issues

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.