Customized safelink url redirector. Transform and Anonymize all hyperlinks to outbound pages. Useful for SEO external links and ADS.
page | source | samples |
---|---|---|
/page/safelink.html | safelink-decode.js layout template compiler |
/page/safelink.html?url=aHR0cHM6Ly... |
registry | link | commands |
---|---|---|
npm | https://www.npmjs.com/package/safelinkify | npm i safelinkify -D |
github | https://github.com/dimaslanjaka/safelink | npm i https://github.com/dimaslanjaka/safelink -D |
tarball | https://github.com/dimaslanjaka/safelink/raw/master/release/safelinkify.tgz | npm i https://github.com/dimaslanjaka/safelink/raw/master/release/safelinkify.tgz -D |
npm install safelinkify -D
yarn install safelinkify --dev
git clone --single-branch --branch main https://github.com/dimaslanjaka/safelink foldername
cd foldername
yarn install # npm install
command | description |
---|---|
yarn start |
serve generated docs |
yarn dev |
watch and build docs |
npm run docs |
build docs |
npm run build |
build dist |
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'
}
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>
const { safelink } = require('safelinkify');
const { default: safelink } = require('safelinkify/dist/safelink');
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>
*/
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.0.0
1.0.1
1.0.2
1.0.3
1.0.5 - 1.0.6
1.0.7
1.0.8 - 1.0.9
1.1.0
1.1.1
1.1.2
1.1.3
1.1.4
parse
now asyncparse
always return stringtsconfig.build.json
excluding test files1.1.5
1.1.6
1.1.7
1.1.8
1.1.9
safelink
and safelinkify
1.1.10
README.md
to lowercase1.1.11
tests
to src-docs
1.1.12
1.1.13
1.2.1
safelink.parse()
) null validationsafelinkify
window.safelink
window.resolveQueryUrl
window.parseQuery