Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const boilerplate = require('./lib/boilerplate')
const serviceworker = require('./lib/serviceWorker')
const link = require('./lib/link/canonical')
const preload = require('./lib/link/preload')
const amphtml = require('./lib/link/amphtml')
const toolbox = require('./lib/toolbox')
const html = require('./lib/html')

Expand All @@ -29,6 +30,7 @@ const html2amp = async (htmlString, options = {}) => {
$ = iframe($, options)
$ = link($)
$ = preload($)
$ = amphtml($, options)
$ = serviceworker($, options)
$ = boilerplate($, options)
htmlString = html($, options)
Expand Down
6 changes: 6 additions & 0 deletions lib/link/amphtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const amphtml = ($) => {
$('link[rel="amphtml"]').remove()
return $
}

module.exports = amphtml
2 changes: 2 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const html = `
<head>
<title>test page</title>
<link rel="canonical" href="https://example.com">
<link rel="amphtml" href="https://example.com/amp/test">
<link rel="stylesheet" href="./styles/test.css" >
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css" >
<script>window.alert('This should be removed.')</script>
Expand All @@ -23,6 +24,7 @@ const expected = `<!DOCTYPE html><html amp=""><head><script async src="https://c




<style amp-custom="">.test{color:red}/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}</style><meta charset="utf-8"><meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"></head>
<body><amp-install-serviceworker src="https://example.com/sw.js" data-iframe-src="https://example.com/install-serviceworker.html" layout="nodisplay"></amp-install-serviceworker><amp-analytics type="googleanalytics"><script type="application/json">{
"vars": {
Expand Down
21 changes: 21 additions & 0 deletions test/link/amphtml.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const cheerio = require('cheerio')
const assert = require('../assert')
const amphtml = require('../../lib/link/amphtml')
const htmlFactory = require('../html')

describe('amphtml', function () {
describe('If there is link tag for amphtml', function () {
const html = htmlFactory({ head: '<link rel="amphtml" href="https://example.com/amp/test">' })
it('should be removed', function () {
const $ = amphtml(cheerio.load(html))
assert($, htmlFactory({ head: '' }))
})
})
describe('If there is link tag for not amphtml', function () {
const html = htmlFactory({ head: '<link rel="other" href="https://example.com/amp/test">' })
it('shouldn\'t be removed', function () {
const $ = amphtml(cheerio.load(html))
assert($, htmlFactory({ head: '<link rel="other" href="https://example.com/amp/test">' }))
})
})
})