Giter Site home page Giter Site logo

metalsmith-jstransformer's Introduction

Metalsmith JSTransformer Plugin NPM version

Build Status Dependency Status Greenkeeper badge

Metalsmith plugin to process files with any JSTransformer.

Installation

npm install --save metalsmith-jstransformer

CLI

If you are using the command-line version of Metalsmith, you can install via npm, and then add the metalsmith-jstransformer key to your metalsmith.json file:

{
  "plugins": {
    "metalsmith-jstransformer": {
      "layoutPattern": "layouts/**",
      "defaultLayout": null
    }
  }
}

JavaScript

If you are using the JS Api for Metalsmith, then you can require the module and add it to your .use() directives:

var jstransformer = require('metalsmith-jstransformer');

metalsmith.use(jstransformer({
  'pattern': '**',
  'layoutPattern': 'layouts/**',
  'defaultLayout': null
}));

Convention

Content File Names

Create files that you would like to act on with JSTransformers with file extensions representing the transformer to use, in the format example.html.<transformer>. For example, if you would like to process with Pug, you would name it src/example.html.pug.

Use multiple transformers by appending additional file extension transformer names at the end. For example, to HTML-Minifier our Pug example above, you would use the filename src/example.html.html-minifier.pug.

Example

The following example uses Pug, so we must additionally install jstransformer-pug:

npm install jstransformer-pug --save
src/example.html.pug
---
pageTitle: My Site
pretty: true
---
doctype html
html(lang="en")
  head
    title= pageTitle
  body
    p This is my site!
Result
<!doctype html>
<html>
  <head>
    <title>My Site</title>
  </head>
  <body>
    <p>This is my site!</p>
  </body>
</html>

Layouts

Declare layouts for your content with the extension of the template engine to be used for the layout, in the src/layouts/** directory.

Example

The following example uses Pug and Markdown-it, so we must additionally install jstransformer-pug and jstransformer-markdown-it:

npm install jstransformer-pug --save
npm install jstransformer-markdown-it --save
src/layouts/default.pug
---
pretty: true
---
doctype html
html
  head
    title My Site
  body!= contents

Within the metadata of content in your src directory, tell it which layout to use:

src/index.md
---
layout: layouts/default.pug
---
This is my **site**!

Result

<!doctype html>
<html>
  <head>
    <title>My Site</title>
  </head>
  <body>
    <p>This is my <strong>site</strong>!</p>
  </body>
</html>

Configuration

.pattern

Render content only matching the given minimatch pattern. Defaults to **.

.layoutPattern

The pattern used to find your layouts, from within the Metalsmith source directory. Defaults to layouts/**.

.defaultLayout

If provided, will be used as the default layout for content that doesn't have a layout explicitly defined. Needs to be the full path to the file, from the Metalsmith source directory. Defaults to null.

.engineOptions

Allows passing in options for the given engines.

engineOptions: {
  // Add our own SASS include paths.
  scss: {
    includePaths: [
      'styles/mystyles',
      'node_modules/bootstrap'
    ]
  }
}

.engineLocals

Allows passing in local variables for the given engines.

engineLocals: {
  // All Twig templates will have the `baseURL` local variable.
  twig: {
    baseURL: 'http://mywebsite.com/'
  }
}

License

MIT

metalsmith-jstransformer's People

Contributors

greenkeeper[bot] avatar klaftertief avatar larrybotha avatar robloach avatar ycherniavskyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

metalsmith-jstransformer's Issues

Add "pattern" option

Only process files that match the given pattern.

If you want it to process only templates:

pattern: templates/**

Test failure on basic fixture

For some reason I got next exception on test execution:

$ npm run test

> [email protected] test /Users/ych/projects/metalsmith-jstransformer
> node test

 • metalsmith-jstransformer

assert.js:81
  throw new assert.AssertionError({
  ^
AssertionError: '(function(){}).call(this);' == '(function(){var a,c;a=42,c=!0}).call(this);'
  at /Users/ych/projects/metalsmith-jstransformer/node_modules/assert-dir-equal/lib/index.js:30:14
  at Array.forEach (native)
  at assertDirEqual (/Users/ych/projects/metalsmith-jstransformer/node_modules/assert-dir-equal/lib/index.js:26:11)
  at Metalsmith.<anonymous> (/Users/ych/projects/metalsmith-jstransformer/test/index.js:35:7)
  at Immediate.<anonymous> (/Users/ych/projects/metalsmith-jstransformer/node_modules/co/index.js:52:14)
  at runCallback (timers.js:666:20)
  at tryOnImmediate (timers.js:639:5)
  at processImmediate [as _immediateCallback] (timers.js:611:5)

The reason is:

$ diff test/fixtures/basic/build/scripts/main.js test/fixtures/basic/expected/scripts/main.js
1c1
< (function(){}).call(this);
\ No newline at end of file
---
> (function(){var a,c;a=42,c=!0}).call(this);
\ No newline at end of file

Installed version of jstransformer and ext:

An in-range update of clone is breaking the build 🚨

Version 2.1.2 of clone was just published.

Branch Build failing 🚨
Dependency clone
Current Version 2.1.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

clone is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 5 commits.

  • 7659418 2.1.2
  • 41ebd1e Add changelog entry for 2.1.2
  • 248c3c3 Fix changelog on master
  • e2a1a10 Merge pull request #90 from ChALkeR/patch-1
  • 2d90739 Avoid using deprecated Buffer constructor

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Options

Allow passing in arguments stating which inputformats/transformers to process.

Extend plugin with possibility to process one transformation per use

Current implementation of metalsmith-jstransformer plugin process all necessary transformation from extensions and apply layout (if passed) at the end in one run.

But what if I need apply only one transformation on first use. Then execute some other plugins. And finally apply all remained transformation with layout.
Example use case:

  1. apply only Markdown transformation on some-blog-post.html.md
  2. execute for example metalsmith-word-count plugin
  3. apply layout with some-blog-post.html content and word count data calculated by previous plugin

May be someone could suggest some already existed solution for this use case.

Fix Metalsmith Watch Support

Thanks for this plugin, I have recently moved from metalsmith-in-place and metalsmith-layouts over to just metalsmith-jstransformer (run in two passes, one for markdown w/o layout and then the second w/ layouts).

Everything works great the first time, but if you're using metalsmith-watch and edit a file, the file will then lose layout on all subsequent builds until you kill the process and restart.

The repro is pretty simple, you can see it here in this gist: https://gist.github.com/fortes/eac83cfcc025e5f5afc4dd0c80e4741c

To run locally: git clone https://gist.github.com/eac83cfcc025e5f5afc4dd0c80e4741c.git repro and see the instructions in README.md

An in-range update of xo is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye 👋 and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The devDependency xo was updated from 0.27.2 to 0.28.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

xo is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v0.28.0

New rules

Improvements

v0.27.2...v0.28.0

Commits

The new version differs by 6 commits.

  • cf98e72 0.28.0
  • d3c5399 Update dependencies
  • f656ee3 Add webpack option (#375)
  • 5a22b77 Add unicorn/string-content rule (#439)
  • ba4efc9 Enable the unicorn/prevent-abbreviations rule
  • 0d63c64 Get extensions and ignores from config files (#436)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Layouts location meaning

In #9 I read that process layouts from src/layouts is design concept.
Could you please explain what is the reason of this decision? What advantages does it give?

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

layouts and in-place

For metalsmith layouts and in-place we've been thinking about switching to jstransformer as our rendering engine: metalsmith/layouts#100. I personally like the modular approach and think it would be an improvement over consolidate. However, since this lib already exists it would maybe be a bit of a duplication of functionality.

We could switch to jstransformer for layouts and in-place and add you as a maintainer there, if you'd be open to that of course. Or maybe both libs have their own unique niche and it would make sense to develop them separately? What do you think?

Publish 0.5.3 to npm

It seems that 0.5.3 isn't published to npm yet. The latest version there is 0.5.2.

Broken images

Hey there,
quick question: could it be possible that jstransformers breaks images, so they can't be displayed anymore?

I told metalsmith-jstransformer this:

.use(jstransformer({
  layoutPattern: 'layouts/**',
  defaultLayout: 'layouts/post.swig'
}))

Pretty basic, everything is working fine, templating-wise - but images get beaten up?!
Help much appreciated, if you need more information, please ask.

Thank you very much & good day to you, Sir!

An in-range update of async is breaking the build 🚨

The dependency async was updated from 3.1.1 to 3.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

async is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

How to get equivalent configuration as with metalsmith-layouts?

So, I'm hoping to switch to this plugin from metalsmith-layouts because I've read that it might be faster, but right now I'm just getting blank outputs.

My current build uses metalsmith-markdown followed by metalsmith-layouts like this:

.use(markdown())
.use(
  layouts({
    engine: 'pug',
    default: 'default.pug',
    directory: 'templates',
    pattern: '**/*.html',
    pretty: true,
    ...pugOptions
  })
)

...and what I've tried so far with this plugin is this:

.use(
  jstransformer({
    pattern: '**',
    layoutPattern: 'templates',
    defaultLayout: 'default.pug',
    engineOptions: {
      pug: { pretty: true, ...pugOptions }
    },
    engineLocals: {
      pug: pugOptions
    }
  })
)

But with that config, markdown content is processed where it exists but the pug layouts are not being applied. FYI, content filenames look like this; they each have a layout key in which I indicate which pug file to pick up.

company_de.md
company_en.md
contact_de.md
contact_en.md
imprint_de.md
imprint_en.md

Any hints?

Sidebar: the pugLocals variable is imported from another file where I prep the pug options and locals as one object, including keys such as basedir which is necessary for includes and extends, and several helper functions. Which also raises the related question: how should I configure engineOptions and engineLocals for pug, which normally takes both options and locals in one object?

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.