diff --git a/.babelrc b/.babelrc index 36a59f6..024dd13 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,3 @@ { - "presets": [ - ["@babel/env"] - ] + "presets": [["@babel/env"]] } diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 9441e73..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: "2" -checks: - method-lines: - config: - threshold: 30 diff --git a/.eslintrc b/.eslintrc index cf1c9cc..8aad754 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,15 +1,6 @@ { - "extends": ["eslint:recommended"], - "rules": { - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "never" - ] - }, + "extends": ["eslint:recommended", "plugin:prettier/recommended"], + "plugins": ["prettier"], "parserOptions": { "sourceType": "module", "ecmaFeatures": { diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..49955e2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "none" +} diff --git a/.travis.yml b/.travis.yml index 83a38c6..bec400d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,4 @@ language: node_js node_js: node notifications: - email: false + email: false diff --git a/README.md b/README.md index 920d589..001f19e 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,17 @@ > 🎯 Set redirect urls in your YAML frontmatter within your [Gatsby](https://www.gatsbyjs.org) site's Markdown files. Mimics the behavior of [jekyll-redirect-from](https://github.com/jekyll/jekyll-redirect-from). -By adding a list of urls to the YAML frontmatter, this plugin creates redirects for all of them at build time. It uses Gatsby's [createRedirect](https://next.gatsbyjs.org/docs/actions/#createRedirect) under the hood. +By adding a list of urls to the YAML frontmatter, this plugin creates redirects for all of them at build time. It uses Gatsby's [createRedirect](https://www.gatsbyjs.org/docs/actions/#createRedirect) under the hood. -## Table of Contents +**Table of Contents** - - [Prerequisites](#prerequisites) - - [Installation](#installation) - - [Server Rendering](#server-rendering) - - [Usage](#usage) - - [Plugin Development](#plugin-development) - - [License](#license) +- [Prerequisites](#prerequisites) +- [Installation](#installation) + - [Server Rendering](#server-rendering) +- [Usage](#usage) +- [Options](#options) +- [Plugin Development](#plugin-development) +- [License](#license) --- @@ -28,6 +29,8 @@ By adding a list of urls to the YAML frontmatter, this plugin creates redirects Plugin assumes the default setup from [gatsby-starter-blog](https://github.com/gatsbyjs/gatsby-starter-blog), with Markdown files processing by [gatsby-transformer-remark](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-remark) and adding a field `slug` for each file node. Head over to gatsby-starter-blog's [gatsby-node.js](https://github.com/gatsbyjs/gatsby-starter-blog/blob/master/gatsby-node.js#L57) file to see how this is done. +If this does not fit your setup, you can [configure the default `query`](#options) being used. + ## Installation ```bash @@ -44,6 +47,8 @@ plugins: [ ] ``` +That's it. See [Usage](#usage). + ### Server Rendering Gatsby's `createRedirect` only creates client-side redirects, so further integration is needed to get server redirects too. Which is highly dependent on your hosting, if you want to have the proper HTML status codes like `301`, Apache needs `.htaccess` rules for that, nginx `rewrite` rules, S3 `RoutingRules` and so on. @@ -68,6 +73,28 @@ redirect_from: --- ``` +## Options + +Plugin does not require to be configured but some additional customization options are available: + +| Option | Default | Description | +| ------ | ------------------- | ------------------------------------------------------------------------------------------------ | +| query | `allMarkdownRemark` | Modify the query being used to get the frontmatter data. E.g. if you use MDX, set `allMdx` here. | + +Add options to the plugins's configuration object in `gatsby-config.js` like so: + +```js +plugins: [ + { + resolve: 'gatsby-redirect-from', + options: { + query: 'allMdx' + } + } + 'gatsby-plugin-meta-redirect' // make sure this is always the last one +] +``` + ## Plugin Development ```bash @@ -80,15 +107,15 @@ npm run build # publishing to npm & GitHub releases # uses https://github.com/webpro/release-it npm run release -npm run release-minor -npm run release-major +npm run release minor +npm run release major ``` ## License The MIT License -Copyright (c) 2018 Matthias Kretschmann +Copyright (c) 2019 Matthias Kretschmann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/package.json b/package.json index 5861aa8..4043ad7 100644 --- a/package.json +++ b/package.json @@ -10,31 +10,34 @@ "build": "babel src --out-dir . --ignore __tests__", "start": "babel -w src --out-dir . --ignore __tests__", "test": "eslint ./src/**/*.js", - "release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive", - "release-minor": "./node_modules/release-it/bin/release-it.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive", - "release-major": "./node_modules/release-it/bin/release-it.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive", + "format": "prettier --write 'src/**/*.{js,jsx}'", + "release": "release-it --non-interactive", + "changelog": "auto-changelog -p", "prepublishOnly": "cross-env NODE_ENV=production npm run build" }, "browserslist": [ - "last 2 versions" + "maintained node versions" ], - "dependencies": { - "chalk": "^2.4.1" - }, + "dependencies": {}, "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/preset-env": "^7.0.0", + "@babel/cli": "^7.4.4", + "@babel/core": "^7.4.5", + "@babel/preset-env": "^7.4.5", + "auto-changelog": "^1.13.0", + "chalk": "^2.4.2", "cross-env": "^5.2.0", - "eslint": "^5.4.0", - "release-it": "^8.0.0" + "eslint": "^5.16.0", + "eslint-config-prettier": "^4.3.0", + "eslint-plugin-prettier": "^3.1.0", + "prettier": "^1.18.2", + "release-it": "^12.3.0" }, "peerDependencies": { "gatsby": ">=2", "gatsby-plugin-meta-redirect": ">=1.1.0" }, "engines": { - "node": "^8.0.0" + "node": ">=8.0.0" }, "repository": "github:kremalicious/gatsby-redirect-from", "bugs": { @@ -44,5 +47,20 @@ "gatsby", "gatsby-plugin", "redirect" - ] + ], + "release-it": { + "scripts": { + "beforeStart": "npm test", + "beforeStage": "npm run changelog" + }, + "git": { + "tagName": "v${version}" + }, + "github": { + "release": true + }, + "npm": { + "publish": true + } + } }