Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-relate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-relate

A gulp plugin to rewrite asset urls relative to a specified path.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

gulp-relate

##Install

$ npm install --save-dev gulp-relate

Usage

Rewrite file references relative to the current file in the stream. Pass gulp-relate an object containing containing a handle used in the source and the path it should rewrite to.

src/index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <link href="assets//css/styles.css">
</head>
<body>
  <p>Oh. My. Glob.</p>
</body>
</html>

gulpfile.js

var gulp = require('gulp');
var relate = require('gulp-relate');

gulp.task('page', function() {
  return gulp.src('./src/*.html')
    .pipe(gulp.dest('./app/'))
    .pipe(relate({assets: './app/assets/'}))
    .pipe(gulp.dest('./app/'))
});

This comes in hand especially well with stream-based template systems, where assets are referenced in layouts and partials agnostic to any specific rendered file. For example, gulp-relate was conceived with this issue in mind from working with Nunjucks.

var gulp = require('gulp');
var data = require('gulp-data');
var fm = require('front-matter');
var render = require('gulp-nunjucks-render');

gulp.task('render', function() {
  return gulp.src('./src/*.html')
    .pipe(data(function(file){
       var content = fm(String(file.contents));
       file.contents = new Buffer(content.body);
       return content.attributes;
    }))
    .pipe(render())
    .pipe(gulp.dest('./app/'))
    .pipe(relate({
      assets: './app/assets/'
    }))
    .pipe(gulp.dest('./app/'))
});

FAQs

Package last updated on 16 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc