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

Add missing trailing slashes to links and URLs #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const React = require("react")
const path = require("path")
const slugify = require("slugify")
const { paginate } = require("gatsby-awesome-pagination")
const { paginate } = require("@decimoseptimo/gatsby-awesome-pagination")

const {
getParentRecursively,
Expand Down Expand Up @@ -70,11 +70,12 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
itemsPerPage: 50,
// itemsPerFirstPage: 3,
pathPrefix: "/",
trailingSlash: true
})

products.forEach(({ node }) => {
createPage({
path: node.slug,
path: node.slug + '/',
component: productView,
context: {
// Data passed to context is available
Expand Down Expand Up @@ -125,6 +126,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
productsCount: products.length,
},
pathPrefix: `/${slugify(i.name.toLowerCase())}`,
trailingSlash: true
})
}

Expand All @@ -138,6 +140,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
tag: tag.fieldValue,
},
pathPrefix: `/tags/${slugify(tag.fieldValue.toLowerCase())}`,
trailingSlash: true
})
})
}
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"version": "0.1.0",
"author": "Kyle Mathews <[email protected]>",
"dependencies": {
"@decimoseptimo/gatsby-awesome-pagination": "^0.3.6-b",
"gatsby": "^2.29.2",
"gatsby-awesome-pagination": "^0.3.6",
"gatsby-image": "^2.8.0",
"gatsby-plugin-favicon": "^3.1.6",
"gatsby-plugin-local-search": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Breadcrumbs = ({ data }) => (
</span>
{data.map((i) => (
<span className="item" key={i._id}>
<Link to={`/${slugify(i.name.toLowerCase())}`}>{i.name}</Link>
<Link to={`/${slugify(i.name.toLowerCase())}/`}>{i.name}</Link>
</span>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidepanel/panels/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Categories = () => {

const ItemLink = ({ name, className='' }) => (
<Link
to={`/${slugify(name.toLowerCase())}`}
to={`/${slugify(name.toLowerCase())}/`}
replace
className={className}
activeClassName="active"
Expand Down
10 changes: 5 additions & 5 deletions src/templates/categoryView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ const CategoryView = (props) => {
const subcategories2 = (
<div className="subcategories">
{subcategories.map((i) => (
<SubcategoryLink to={`/${slugify(i.name.toLowerCase())}`} key={i._id}>
<SubcategoryLink to={`/${slugify(i.name.toLowerCase())}/`} key={i._id}>
{i.name}
</SubcategoryLink>
))}
</div>
)

const handlePageChange = (e, d) => {
d.activePage === 1
? navigate(`/${slugify(category.name.toLowerCase())}`)
: navigate(`/${slugify(category.name.toLowerCase())}/${d.activePage}`)
const handlePageChange = (page) => {
page === 1
? navigate(`/${slugify(category.name.toLowerCase())}/`)
: navigate(`/${slugify(category.name.toLowerCase())}/${page}/`)
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/templates/productIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ProductIndex = (props) => {
const products = props.data.allProductsJson.edges

const handlePageChange = (page) => {
page === 1 ? navigate(`/`) : navigate(`/${page}`)
page === 1 ? navigate(`/`) : navigate(`/${page}/`)
}

return (
Expand Down