1.2.2 • Published 7 months ago

safelinkify v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Safelinkify

npm version www.webmanajemen.com LICENSE GitHub language count Github Workflow GitHub forks GitHub stars

Customized safelink url redirector. Transform and Anonymize all hyperlinks to outbound pages. Useful for SEO external links and ADS.

Our Production

pagesource
https://www.webmanajemen.com/page/safelink.htmlsafelink-decode.js layout template compiler

Installation

Bundles

registrylinkcommands
npmhttps://www.npmjs.com/package/safelinkifynpm i safelinkify
githubhttps://github.com/dimaslanjaka/safelinknpm i https://github.com/dimaslanjaka/safelink
tarballhttps://github.com/dimaslanjaka/safelink/raw/master/release/safelinkify.tgznpm i https://github.com/dimaslanjaka/safelink/raw/master/release/safelinkify.tgz

npm

npm install safelinkify --production

yarn

yarn install safelinkify --production=true

Development

git clone --single-branch --branch main https://github.com/dimaslanjaka/safelink foldername
cd foldername
# install dependents
yarn install
# or
npm install
commanddescription
yarn startwatch src-docs and start server
watch src and compile tsc webpack
tscbuild definition and js files
webpackbuild safelink script

Usages

Setup options:

const options = {
  // exclude patterns (dont anonymize these patterns)
  exclude: ['domain.com', /another.domain.com/, /https?:\/\/?(?:([^*]+)\.)?webmanajemen\.com/, /([a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?[.])*webmanajemen\.com/],
  // url redirector
  redirect: 'https://www.webmanajemen.com/page/safelink.html?url=',
  // debug
  verbose: false,
  // encryption type = 'base64' | 'aes'
  type: 'base64',
  // password aes, default = root
  password: 'unique-password'
}

Browser

script location: node_modules/safelinkify/dist/bundle.min.js.

Call Core Script:

<script src="dist/bundle.min.js"></script>
<!--or using rawgit-->
<script src="https://raw.githack.com/dimaslanjaka/safelink/main/dist/bundle.min.js"></script>
<!--or using statically-->
<script src="https://cdn.statically.io/gh/dimaslanjaka/safelink/main/dist/bundle.min.js"></script>

Execute functions:

<script>
  const sf = new safelink(options);
  // automated safelinkify all hyperlinks in body
  sf.parse(document.querySelector('body')).then((result)=>{
    console.log(result);
    // in page redirector
    sf.resolveQueryUrl(window.location.href);
  });
</script>

NodeJS

Reference Examples:

Import list

const { safelink } = require('safelinkify');
const { default: safelink } = require('safelinkify/dist/safelink');

Usages Example

import safelinkify from 'safelinkify';
// const safelinkify = require('safelinkify')
const sf = new safelinkify.safelink(options);
const processedExternalLinks = sf.parse(`
<a href="www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="http://www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="https://www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="www.example.com/page.php/404" ....></a>
<a href="http://external.domain.com">internal</a>
<a href="http://www.webmanajemen.com">internal</a>
<a href="http://webmanajemen.com">internal</a>
<a href="#http://webmanajemen.com">#internal</a>
<a href="?http://webmanajemen.com">?internal</a>
<a href="">internal</a>
`);
processedExternalLinks.then(console.log);

/*
<a href="www.example.com/page.php?id=xxxx&name=yyyy" ....>external</a>
<a href="https://www.webmanajemen.com/page/safelink.html?url=aHR0cDovL3d3dy5leGFtcGxlLmNvbS9wYWdlLnBocD9pZD14eHh4Jm5hbWU9eXl5eQ==" ....>external</a>
<a href="https://www.webmanajemen.com/page/safelink.html?url=aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vcGFnZS5waHA/aWQ9eHh4eCZuYW1lPXl5eXk=" ....>external</a>
<a href="www.example.com/page.php/404" ....></a>
<a href="http://external.domain.com">internal</a>
<a href="http://www.webmanajemen.com">internal</a>
<a href="http://webmanajemen.com">internal</a>
<a href="#http://webmanajemen.com">#internal</a>
<a href="?http://webmanajemen.com">?internal</a>
<a href="">internal</a>
*/

Using gulp

Reference Examples:

Usages:

import gulp from 'gulp'
import sf from 'safelinkify'
import { toUnix, join } from 'upath'
import through2 from 'through2'

// folder to scan
const destDir = join(__dirname, 'build')
// scan external link to safelink from dest dir
gulp.task('safelink', () => {
  const safelink = new sf.safelink({
    // exclude patterns (dont anonymize these patterns)
    exclude: [
      /https?:\/\/?(?:([^*]+)\.)?webmanajemen\.com/,
      /([a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?[.])*webmanajemen\.com/
    ],
    // url redirector
    redirect: 'https://www.webmanajemen.com/page/safelink.html?url=',
    // debug
    verbose: false,
    // encryption type = 'base64' | 'aes'
    type: 'base64',
    // password aes, default = root
    password: 'unique-password'
  })
  return gulp
    .src(['**/*.html'], {
      cwd: destDir,
      ignore: [
        // exclude non-website and react production files
        '**/tmp/**',
        '**/node_modules/**',
        '**/monsters/**/*',
        '**/attendants/**/*',
        '**/materials/**/*',
        '**/scenic-spots/**/*',
        '**/static/**/*'
      ]
    })
    .pipe(
      through2.obj(async (file, _enc, next) => {
        // drop null
        if (file.isNull()) return next()
        // do safelinkify
        const content = String(file.contents)
        const parsed = await safelink.parse(content)
        if (parsed) {
          file.contents = Buffer.from(parsed)
          next(null, file)
        } else {
          console.log(
            'cannot parse',
            toUnix(file.path).replace(toUnix(process.cwd()), '')
          )
          next()
        }
      })
    )
    .pipe(gulp.dest(destDir))
})
1.2.2

7 months ago

1.2.1

8 months ago

1.1.19

8 months ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.13

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago