Skip to content
This repository has been archived by the owner on Dec 28, 2019. It is now read-only.
/ SUSH Public archive

Simple URL Shortener (can be provided from a static HTML server)

Notifications You must be signed in to change notification settings

3846masa/SUSH

Repository files navigation

SUSH | Simple URL Shortener

SUSH

standard-readme compliant Build Status codecov

🍣 Simple URL Shortener which can be provided from a static HTML server.

This is the URL shortener which can be provided from a static HTML server.

When you access http://your.domain/#/example, SUSH gets ID from hash (/example), and redirect to URL associated with ID.

You can provide URL shortener via GitHub Pages or any HTTP server, because it is able to work on browser.

Table of Contents

Install

For HTML

Insert script tags in your HTML.

<script src="https://unpkg.com/sush"></script>
<!-- Add script tags of SUSH Plugins -->

Via Node.js

npm install --save sush [...SUSH_PLUGINS]

Usage

Via HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Redirecting...</title>
</head>
<body>
  <p>Redirecting...</p>

  <!-- SUSH scripts -->
  <script src="https://unpkg.com/sush"></script>
  <script src="https://unpkg.com/sush-plugin-trim-id"></script>
  <script src="https://unpkg.com/sush-plugin-spreadsheet"></script>
  <script src="https://unpkg.com/sush-plugin-google-analytics"></script>
  <script src="https://unpkg.com/sush-plugin-redirect"></script>

  <!-- main script -->
  <script>
    var sheetUrl =
      'https://docs.google.com/spreadsheets/d/XXXXXXX/edit#gid=XXX';

    var sush = new SUSH({ mode: 'lower' });

    sush.flow([
      SUSH.$trimId({ head: 1 }),
      SUSH.$spreadsheet({ sheetUrl: sheetUrl }),
      SUSH.$googleAnalytics({ analyticsId: 'UA-XXXXXXXX-1' }),
      SUSH.$redirect({ fallback: '/404/' })
    ])
    .catch((err) => {
      console.error(err);
    });
  </script>
</body>
</html>

Via Node.js (e.g. Browserify, Webpack)

import SUSH from 'sush';
import trimId from 'sush-plugin-trim-id';
import spreadsheet from 'sush-plugin-spreadsheet';
import analytics from 'sush-plugin-google-analytics';
import redirect from 'sush-plugin-redirect';

const sheetUrl =
  'https://docs.google.com/spreadsheets/d/XXXXXX_XXXXXX/edit#gid=0';

const sush = new SUSH();
sush.flow([
  trimId({ head: 1 }),
  spreadsheet({ sheetUrl: sheetUrl }),
  analytics({ analyticsId: 'UA-XXXXXXXX-1' }),
  redirect({ fallback: '/404.html' })
]).catch((err) => {
  console.error(err.stack || err);
});

Plugins

Contribute

PRs accepted.

License

MIT © 3846masa