Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync #5

Merged
merged 16 commits into from
Sep 11, 2019
Merged
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: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node
- image: circleci/node:latest-browsers
steps:
# Checkout repository
- checkout
Expand Down
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ module.exports = {
},
extends: [
'@nuxtjs'
]
],
globals: {
page: true,
browser: true,
context: true,
jestPuppeteer: true,
},
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.1.0 (2019-09-10)

Initial Release
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
## Docs
* Getting Started
* [Introduction](docs/README.md)
* [Setup](docs/setup.md)
* [Middleware](docs/middleware.md)
* [Usage](docs/usage.md)
* [Styling](docs/styling.md)
* [Setup](docs/guide/setup.md)
* [Middleware](docs/guide/middleware.md)
* [Usage](docs/guide/usage.md)
* [Styling](docs/guide/styling.md)
* Reference
* [Tags](docs/tags.md)
* [API](docs/api/readme.md)
* [Options](docs/api/options.md)
* [AMP elements](docs/api/amp-elements.md)
* [Components](docs/api/components.md)


## Setup

Expand Down
4 changes: 2 additions & 2 deletions docs/api/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# API

- [Options](./options.md)
- [AMP elements](./amp-elements)
- [Components](./components)
- [AMP elements](./amp-elements.md)
- [Components](./components.md)
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "vuepress build"
},
"devDependencies": {
"vuepress": "^1.0.3"
"vuepress": "^1.0.4"
}
}

117 changes: 59 additions & 58 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -810,18 +810,18 @@
source-map "~0.6.1"
vue-template-es2015-compiler "^1.9.0"

"@vuepress/core@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/core/-/core-1.0.3.tgz#a32aedca770ee763c406a74abab2bc4fa42e9bdc"
integrity sha512-VUzjf2LMxy+DjiDs2QUO0R4zXATn0db7ClDETzc5D+HH08J2YwUO2YNHgIObHMyuihmDozesbYBiDp0kIxAqCw==
"@vuepress/core@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/core/-/core-1.0.4.tgz#623c5cc4d9865e60a11917af01cdaa1b41dbe5d2"
integrity sha512-ZF3e7nHCSREM0Yq/LyMmZEL3Qv85JVrqIgCHlv3goW9Ay5gn/YLy1JaG2+/1JgDFfw5Hr+qmtGs3aExGSeOS+Q==
dependencies:
"@babel/core" "^7.0.0"
"@vue/babel-preset-app" "^3.1.1"
"@vuepress/markdown" "^1.0.3"
"@vuepress/markdown-loader" "^1.0.3"
"@vuepress/plugin-last-updated" "^1.0.3"
"@vuepress/plugin-register-components" "^1.0.3"
"@vuepress/shared-utils" "^1.0.3"
"@vuepress/markdown" "^1.0.4"
"@vuepress/markdown-loader" "^1.0.4"
"@vuepress/plugin-last-updated" "^1.0.4"
"@vuepress/plugin-register-components" "^1.0.4"
"@vuepress/shared-utils" "^1.0.4"
autoprefixer "^9.5.1"
babel-loader "^8.0.4"
cache-loader "^3.0.0"
Expand Down Expand Up @@ -853,65 +853,65 @@
webpack-merge "^4.1.2"
webpackbar "3.2.0"

"@vuepress/markdown-loader@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/markdown-loader/-/markdown-loader-1.0.3.tgz#8e63e66d0bb1ec75ee564424bdf8e7ee38077b63"
integrity sha512-2/023ghXi+7XHeHRbcXpUeWAERtSSCopPPdZqFV5/aIhW+Lv1Bl2iV1QfR2jKwlnZO/6g3HYMBq2GJaTNw0QLg==
"@vuepress/markdown-loader@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/markdown-loader/-/markdown-loader-1.0.4.tgz#2c54772889b19dcb8b2703cadd6088b96d748adb"
integrity sha512-kgePl2Oo0q8VGZe3tiuj88UJF1Mpn8Hp7bg0SSpa70WO6ne4S5u8H1M+80fClbuLLoyc5jtb92XcDkfzlnCurw==
dependencies:
"@vuepress/markdown" "^1.0.3"
"@vuepress/markdown" "^1.0.4"
loader-utils "^1.1.0"
lru-cache "^5.1.1"

"@vuepress/markdown@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/markdown/-/markdown-1.0.3.tgz#633e2b69ee7c00a1aaa8b71584a50e4e1518edc6"
integrity sha512-kauU0EZk5+Ju74MtxiBiQ6HAbcchr8UjbURHSHwJe1k6W0fy0wyQ0ND5EILLhKZl1KhZeHGGDKBW385ruRKfcQ==
"@vuepress/markdown@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/markdown/-/markdown-1.0.4.tgz#ab0a403e78acb36fa24d90061191caadad7cb77c"
integrity sha512-xBEzq09UrAnQm1W7UVJ9UDraBTYJUyFj0aJOBwzKoG0QtGzK9ah6WTCeKOskvzLYQkqToVtig82q2uoKU9PH2A==
dependencies:
"@vuepress/shared-utils" "^1.0.3"
"@vuepress/shared-utils" "^1.0.4"
markdown-it "^8.4.1"
markdown-it-anchor "^5.0.2"
markdown-it-chain "^1.3.0"
markdown-it-emoji "^1.4.0"
markdown-it-table-of-contents "^0.4.0"
prismjs "^1.13.0"

"@vuepress/plugin-active-header-links@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-active-header-links/-/plugin-active-header-links-1.0.3.tgz#94cae9a4e554fb7989461741748938efaa2fd65e"
integrity sha512-hUxGVfiQs/ywDykklSzMXT4evHe1w/DB5PMtS2LIig3sj5K+gAgNiu6L9SjXFTrYPxp9fWkYmkKPf7guV2QuRw==
"@vuepress/plugin-active-header-links@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-active-header-links/-/plugin-active-header-links-1.0.4.tgz#877d3b607597f9902deaac5184d79b6b2f6139b2"
integrity sha512-sYT1yvBeUMW9cTHVzrKl1mzCmMQCwROVTe2B7N1UvtLpYT+xvu33Uttbk9Aj/p5PxqGH65vaTBKaQoGkdyMp3g==
dependencies:
lodash.throttle "^4.1.1"

"@vuepress/plugin-last-updated@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-last-updated/-/plugin-last-updated-1.0.3.tgz#b9e3cd2d7cc27d0e70e7ea2194c171607bd61493"
integrity sha512-GMD9g8Lw1ASdBiRZgQotkZqOgsGuvX33sDnmRuYjUcO4f6Lo+m8JZsOTStNjcquCvykucbjYqU1LQTyGAMyZWw==
"@vuepress/plugin-last-updated@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-last-updated/-/plugin-last-updated-1.0.4.tgz#ff50eaf74a9b1e27702b411532efd74801256941"
integrity sha512-HOUj4XJPnoAlYdeo7GPXVXNjC/A28u8bwvIBi92w5uBlNyYs4tjZMso/WVaMhH9Q7touYIp5PCcZTzACoOMNwg==
dependencies:
cross-spawn "^6.0.5"

"@vuepress/plugin-nprogress@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-nprogress/-/plugin-nprogress-1.0.3.tgz#a0d6913193c933171b4695bf153efb0c29a76421"
integrity sha512-F7+R9EcBV0MT7dn06sUhGpsE7dzkT/eVLBNDqN3hDBedhu1XV8Ch5JYYGXKGFHrRdtDmiwyvEl4W6L6uzCVT4Q==
"@vuepress/plugin-nprogress@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-nprogress/-/plugin-nprogress-1.0.4.tgz#65628758a310552806c266d54a135555fbf67276"
integrity sha512-hhykZwb5Sh3oVIOz7nrjF59KImH+N6V4HphKni740G9LOu2577JU/Jf3MOxqTqRTAnrS73QvrE1dv6xJJ/HQqg==
dependencies:
nprogress "^0.2.0"

"@vuepress/plugin-register-components@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-register-components/-/plugin-register-components-1.0.3.tgz#5cbfd0947c904a0f4c1911746fb5586520ed9b9d"
integrity sha512-6vlXEuaEJtV1EIudcVzJciJf0HRAcWRd6ViB9WO87enkqeT+bR32VZENqcN43RyF8vPP+mmZ/2eDUpvM3J6a2w==
"@vuepress/plugin-register-components@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-register-components/-/plugin-register-components-1.0.4.tgz#1a714d393842b5454443bbe3aa2b91b64995eb93"
integrity sha512-v5K2a8dsmIaynHh6LnFEbSfoCR8nM03vX+vS90iYPMdcE44DTL1d56YRf0zsRD0NN96gkIjcRA3NpSY5Oe8cGg==
dependencies:
"@vuepress/shared-utils" "^1.0.3"
"@vuepress/shared-utils" "^1.0.4"

"@vuepress/plugin-search@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-search/-/plugin-search-1.0.3.tgz#f8cd98380cc00db067fb243e4fd298c6b8b7179a"
integrity sha512-CD4G6BrKtS6JS9DzPMbwwovanaKMhj/KN6Bv7P5oY5inWTl3lE9KOjzr1YUkoA6wL6f69EfdB5B7cdO2d47n/w==
"@vuepress/plugin-search@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/plugin-search/-/plugin-search-1.0.4.tgz#991a896cacb8f0bd6dc5789f8a2d93be32ae0abd"
integrity sha512-Jx+PDjkOiksX/E3fEQNbj2GP/g75giv8CoFl+9DyM3kxdDlUAC3N9Sd41SrYJ9lYlXG3ICEQAUyHYSjVvYKAuA==

"@vuepress/shared-utils@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/shared-utils/-/shared-utils-1.0.3.tgz#224d2fc10fcf26d871eae8dd93b810616731123f"
integrity sha512-E9kh+nk+E0X6GTONXK1OWeY7Yyl/bUkWltmdh89f7hcSn2MxuBmlph4JdtZKrTK2m+9EqzpVR+CYanGjTA/ZQA==
"@vuepress/shared-utils@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/shared-utils/-/shared-utils-1.0.4.tgz#520c5a6ae263accd29efc8dfad727ad62052ded2"
integrity sha512-64Rlyb6HOhoeJDa6BbTGKVEgFqIJWdr6vO3o+wmAgKSvX7sqdT0Hs6ETjtt9jWSbjeQTjwP1XbXwKrpEY2jWKw==
dependencies:
chalk "^2.3.2"
diacritics "^1.3.0"
Expand All @@ -923,15 +923,16 @@
semver "^6.0.0"
upath "^1.1.0"

"@vuepress/theme-default@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@vuepress/theme-default/-/theme-default-1.0.3.tgz#a92025d9be1705ef7b95c53365a8ba3d917b6023"
integrity sha512-rS12CdMQwpSD7RI9XCM1gko13uPKhbVlbaxb7bd6ozjOQm4Iy1qAAyoZredRl1Sx29QvvcXZxLMGzAqx98GMCw==
"@vuepress/theme-default@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@vuepress/theme-default/-/theme-default-1.0.4.tgz#a74fb0cf093ca8b78b4ef1157d2130505606e1d2"
integrity sha512-H6tZFgxIWYNnjLJVmcWBolWNy15c0keEY0ck2Lv3KkuzfkrABPbOuBLGcdG7vPAJBT+BDKpsJHoBpfGF7KwY1g==
dependencies:
"@vuepress/plugin-active-header-links" "^1.0.3"
"@vuepress/plugin-nprogress" "^1.0.3"
"@vuepress/plugin-search" "^1.0.3"
"@vuepress/plugin-active-header-links" "^1.0.4"
"@vuepress/plugin-nprogress" "^1.0.4"
"@vuepress/plugin-search" "^1.0.4"
docsearch.js "^2.5.2"
lodash "^4.17.15"
stylus "^0.54.5"
stylus-loader "^3.0.2"
vuepress-plugin-container "^2.0.0"
Expand Down Expand Up @@ -4179,7 +4180,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.3, lodash@^4.17.5:
lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.5:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down Expand Up @@ -6990,13 +6991,13 @@ vuepress-plugin-container@^2.0.0:
dependencies:
markdown-it-container "^2.0.0"

vuepress@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/vuepress/-/vuepress-1.0.3.tgz#7c744061b5a3244ab86d49ac8d66417258509f13"
integrity sha512-+wCbyhZjaboY6VGBceai+JCdho96ZO9hVFHLnGGsj1/Zt2sKHrwWwV7lvbBO9y/IGib0YYpifpEJcpzvy3MDVg==
vuepress@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/vuepress/-/vuepress-1.0.4.tgz#0f02f67ff6dec02fa9c500c39dbe8c8203db87a0"
integrity sha512-QzJkRGGOv3+j7MNsjbCLGe5XaAl5fClndQa2woT8j6b+Cc7S1MOHNlITH6zDZ1eH7XETlNI3BmTZ/nJ2aoHyIw==
dependencies:
"@vuepress/core" "^1.0.3"
"@vuepress/theme-default" "^1.0.3"
"@vuepress/core" "^1.0.4"
"@vuepress/theme-default" "^1.0.4"
cac "^6.3.9"
envinfo "^7.2.0"
opencollective-postinstall "^2.0.2"
Expand Down
11 changes: 11 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
launch: {
// to use google chrome, install puppeteer with PUPPETEER_SKIP_CHROMIUM_DOWNLOAD env
// and uncomment next line
// executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
args: [
'–no-sandbox',
'–disable-setuid-sandbox'
]
}
}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testEnvironment: 'node',
preset: 'jest-puppeteer',
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.js',
Expand Down
6 changes: 5 additions & 1 deletion lib/amp/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ const createCustomHead = originalHead => function customHead () {
const { amp, ...query } = this.$route.query

if (!head.link.find(l => l.rel === 'canonical' || l.hid === 'canonical')) {
const path = this.$isAMP && this.$ampMode !== 'only'
? this.$route.path.replace(/^\/amp(\/.*)?/, '$1')
: this.$route.path

head.link.push({
rel: 'canonical',
hid: 'canonical',
href: origin + this.$route.path + stringifyQuery(query)
href: origin + path + stringifyQuery(query)
})
}

Expand Down
8 changes: 7 additions & 1 deletion lib/amp/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export default function ({ route, req }, inject) {
break
}

inject('req', req || {})
const $request = req || {}
/**
* This will use to detect amp request on render hook
*/
$request.isAMP = isAMP

inject('req', $request)
inject('isAMP', isAMP)
inject('ampMode', ampMode)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const AMPBoilerplate = '<style amp-boilerplate>body{-webkit-animation:-amp-start
'<script async src="https://cdn.ampproject.org/v0.js"></script>'

const scriptPattern = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi
const ampBodyPattern = /<amp-body[^>]*>([.\S\s]*)<\/amp-body>/g
const ampBodyPattern = /<amp-body[^>]*>([.\S\s]*)<\/amp-body>/

module.exports = function (moduleOptions) {
const options = {
Expand Down Expand Up @@ -47,8 +47,8 @@ function processRoutes (routes) {
async function registerValidator (options) {
const amphtmlValidator = require('amphtml-validator')
const validator = await amphtmlValidator.getInstance()
this.nuxt.hook('render:route', (url, { html }) => {
const isAMP = html.includes('data-n-head="amp"')
this.nuxt.hook('render:route', (url, { html }, { req }) => {
const isAMP = req.isAMP

if (isAMP) {
const result = validator.validateString(html)
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nuxtjs/amp",
"version": "0.0.0",
"version": "0.1.0",
"description": "AMP Module for Nuxt",
"license": "MIT",
"contributors": [
Expand Down Expand Up @@ -32,8 +32,8 @@
"qs": "^6.8.0"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@nuxtjs/eslint-config": "^1.1.2",
Expand All @@ -51,9 +51,10 @@
"get-port": "latest",
"husky": "^3.0.5",
"jest": "^24.9.0",
"jest-puppeteer": "^4.3.0",
"nuxt-edge": "^2.10.0-26128283.86179c41",
"puppeteer": "^1.19.0",
"request": "latest",
"request-promise-native": "latest",
"standard-version": "^7.0.0",
"vue-tweet-embed": "^2.3.0"
}
Expand Down
Loading