diff --git a/.circleci/config.yml b/.circleci/config.yml index 78c4e41c..b42a91ea 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/node + - image: circleci/node:latest-browsers steps: # Checkout repository - checkout diff --git a/.eslintrc.js b/.eslintrc.js index c8a98297..7770eef6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,5 +6,11 @@ module.exports = { }, extends: [ '@nuxtjs' - ] + ], + globals: { + page: true, + browser: true, + context: true, + jestPuppeteer: true, + }, } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..52d5148f --- /dev/null +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index aeb781fd..a60f571a 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/api/readme.md b/docs/api/readme.md index fabf940e..d2f08138 100644 --- a/docs/api/readme.md +++ b/docs/api/readme.md @@ -1,5 +1,5 @@ # API - [Options](./options.md) -- [AMP elements](./amp-elements) -- [Components](./components) +- [AMP elements](./amp-elements.md) +- [Components](./components.md) diff --git a/docs/package.json b/docs/package.json index 6658805a..fcd987a5 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,7 +5,7 @@ "build": "vuepress build" }, "devDependencies": { - "vuepress": "^1.0.3" + "vuepress": "^1.0.4" } } diff --git a/docs/yarn.lock b/docs/yarn.lock index dd093607..06334f2d 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -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" @@ -853,21 +853,21 @@ 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" @@ -875,43 +875,43 @@ 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" @@ -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" @@ -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== @@ -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" diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js new file mode 100644 index 00000000..abaedba6 --- /dev/null +++ b/jest-puppeteer.config.js @@ -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' + ] + } +} diff --git a/jest.config.js b/jest.config.js index 2057886c..bbac01af 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - testEnvironment: 'node', + preset: 'jest-puppeteer', collectCoverage: true, collectCoverageFrom: [ 'lib/**/*.js', diff --git a/lib/amp/middleware.js b/lib/amp/middleware.js index d3230890..8e409088 100644 --- a/lib/amp/middleware.js +++ b/lib/amp/middleware.js @@ -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) }) } diff --git a/lib/amp/plugin.js b/lib/amp/plugin.js index 847d96dd..20401198 100644 --- a/lib/amp/plugin.js +++ b/lib/amp/plugin.js @@ -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) } diff --git a/lib/module.js b/lib/module.js index 528ba195..f720a4c7 100644 --- a/lib/module.js +++ b/lib/module.js @@ -10,7 +10,7 @@ const AMPBoilerplate = '