diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6783d2e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,9 @@ +# FUNDING.yml - GitHub sponsor button configuration +# Copyright (C) 2019 Kaz Nishimura +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +--- +custom: + - https://salt.bountysource.com/checkout/amount?team=vx68k diff --git a/.vscode/settings.json b/.vscode/settings.json index e10fcf4..95b5622 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { - "files.exclude": { - "**/*.rej": true, - "**/*.orig": true, - "**/*~": true - } + "files.exclude": { + "**/*.rej": true, + "**/*.orig": true, + "**/*~": true } +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..df06b33 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +This file documents the current guidelines for contributing. + +# Conventions + +The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, +“SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be +interpreted as described in [BCP 14][] when, and only when, they appear in all +capitals, as shown here. + +[BCP 14]: https://tools.ietf.org/html/bcp14 + +# Pull request guidelines + +## File encoding + +Unless mandated by the media type, a file SHOULD be encoded either in `UTF-8` +(preferred) or in `US-ASCII`, and if it would be in `UTF-8`, it MUST NOT +contain any BOM (U+FEFF). + +## End-of-line convention + +Unless mandated by the media type, each line of a file SHOULD end with a single +LF (U+000A). diff --git a/README.md b/README.md index 8c7cc1f..068d3d1 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ This file documents the `redirect.js` script. # Description -The `redirect.js` script redirects modern web browsers to another location -without any server configuration. +The `redirect.js` script redirects web browsers to another location *without +any server configuration*. It is *not a script for Node.js* but for web browsers. [![(License)](https://img.shields.io/badge/license-MIT-blue.svg)][MIT] diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..e4ba6c2 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,39 @@ +# azure-pipelines.yml - configuration for Azure Pipelines +# Copyright (C) 2020 Kaz Nishimura +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +--- +trigger: + - master + - release/* + - feature/* +stages: + - stage: Default + jobs: + - job: Build + pool: + vmImage: ubuntu-latest + steps: + - task: NodeTool@0 + - bash: | + npm test + displayName: Test + - task: PublishTestResults@2 + condition: succeededOrFailed() + - stage: Release + dependsOn: Default + condition: + and(succeeded(), + startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')) + jobs: + - job: Upload + pool: + vmImage: ubuntu-latest + steps: + - task: NodeTool@0 + - task: Npm@1 + inputs: + command: publish + publishEndpoint: npmjs diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index a6424ca..a0032c3 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -12,13 +12,31 @@ definitions: steps: - step: &test name: Test + image: node:8 caches: - node script: + - npm config set unsafe-perm true - npm install - npm test -image: node:8 + - step: &package + name: Packaging + image: node:8 + caches: + - node + script: + - npm config set unsafe-perm true + - npm install + - npm pack + artifacts: + - "*.tgz" pipelines: branches: - default: + master: + - step: *test + deployment/test: + - step: + <<: *package + pull-requests: + "**": - step: *test diff --git a/prepack.sh b/etc/prepack.sh similarity index 100% rename from prepack.sh rename to etc/prepack.sh diff --git a/package.json b/package.json index 826990a..3932177 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,29 @@ { "name": "@kazssym/redirect", - "version": "1.0.0-beta.1", + "version": "1.0.0-beta.4", + "description": "Module script to redirect web browsers to another location without any server configuration.", + "keywords": [ + "browser", + "es2015", + "module" + ], "homepage": "https://vx68k.bitbucket.io/redirect.js/", "license": "MIT", + "author": { + "name": "Kaz Nishimura", + "email": "kazssym@linuxfront.com" + }, "files": [ - "prepack.sh", + "etc/*", "**/*.js" ], "browser": {}, "repository": { - "type": "hg", - "url": "https://bitbucket.org/vx68k/redirect.js" + "type": "git", + "url": "https://github.com/vx68k/redirect.js.git" }, "scripts": { - "prepack": "sh ./prepack.sh" + "prepack": "sh ./etc/prepack.sh" }, "devDependencies": { "terser": "~4" diff --git a/redirect.js b/redirect.js index c90028b..58655ef 100644 --- a/redirect.js +++ b/redirect.js @@ -1,4 +1,4 @@ -// redirect.js - browser script to redirect the browser to a new location +// redirect.js - module script to redirect web browsers to another location // Copyright (C) 2019 Kaz Nishimura // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -24,7 +24,7 @@ // NOTE: this file is a module script. /** - * Browser script to redirect the browser to a new location. + * Module script to redirect web browsers to another location. * * This script can be loaded in a *redirecting* HTML file as follows: * @@ -50,6 +50,31 @@ */ const PACKAGE_VERSION = "@PACKAGE_VERSION@"; + /** + * Module name. + * + * @private + */ + const MODULE_NAME = "redirect.js"; + +/** + * Returns the canonical link of the document. + * + * @return {HTMLLinkElement} the canonical link + */ +export function getCanonicalLink() +{ + let root = document.documentElement; + for (let link of root.getElementsByTagName("link")) { + for (let type of link.relList) { + if (type.toLowerCase() == "canonical") { + return link; + } + } + } + return null; +} + /** * Redirects the browser to the location specified by the `data-new-location` * attribute of the root element or the `canonical` link of the document, @@ -66,13 +91,9 @@ export function run() newLocation = root.dataset.newLocation; } if (newLocation == null) { - for (let link of root.getElementsByTagName("link")) { - for (let type of link.relList) { - if (type.toLowerCase() == "canonical") { - newLocation = link.href; - break; - } - } + let link = getCanonicalLink(); + if (link != null) { + newLocation = link.href; } } @@ -82,6 +103,5 @@ export function run() } } -console.info("Loaded: %s (%s %s)", "redirect.js", - PACKAGE_NAME, PACKAGE_VERSION); +console.info("Loaded: %s (%s %s)", MODULE_NAME, PACKAGE_NAME, PACKAGE_VERSION); run(); diff --git a/upload.sh b/upload.sh new file mode 100755 index 0000000..a140d52 --- /dev/null +++ b/upload.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# upload.sh - file uploader for Bitbucket Cloud +# Copyright (C) 2018 Kaz Nishimura +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. + +REPOSITORY=vx68k/netbeans-bitbucket-plugin + +test -n "$USERNAME" || exit 0 + +for file in "$@"; do + FILES="$FILES --form files=@\"$file\"" +done +test -n "$FILES" || exit 1 + +exec curl --silent --show-error --user "$USERNAME${PASSWORD+:$PASSWORD}" \ + --request POST $FILES \ + https://api.bitbucket.org/2.0/repositories/$REPOSITORY/downloads