mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-02-14 21:10:41 +01:00
tweak mechanism for auto-attaching project images
This commit is contained in:
parent
05940ae5b7
commit
e1c36e3cff
@ -1,6 +1,5 @@
|
|||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
// const path = require('path')
|
|
||||||
const remark = require('remark')
|
const remark = require('remark')
|
||||||
const parse = require('remark-parse')
|
const parse = require('remark-parse')
|
||||||
const html = require('remark-html')
|
const html = require('remark-html')
|
||||||
@ -84,19 +83,26 @@ exports.onPreBootstrap = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add repos to front page's context
|
// Add pageContext
|
||||||
//
|
//
|
||||||
exports.onCreatePage = async ({ page, actions }) => {
|
exports.onCreatePage = async ({ page, actions }) => {
|
||||||
const { createPage } = actions
|
const { createPage, deletePage } = actions
|
||||||
|
|
||||||
if (page.path === '/')
|
// Regex for auto-attaching project images to pages based on slug.
|
||||||
createPage({
|
// Image file names follow the pattern slug-01.png.
|
||||||
...page,
|
// Regex inspiration from https://stackoverflow.com/a/7124976
|
||||||
context: {
|
const imageRegex = `/${page.path.replaceAll('/', '')}+?(?=-\\d)/`
|
||||||
...page.context,
|
|
||||||
repos
|
deletePage(page)
|
||||||
}
|
createPage({
|
||||||
})
|
...page,
|
||||||
|
context: {
|
||||||
|
...page.context,
|
||||||
|
imageRegex,
|
||||||
|
// Add repos only to front page's context
|
||||||
|
...(page.path === '/' && { repos })
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.onCreateNode = ({ node, actions }) => {
|
exports.onCreateNode = ({ node, actions }) => {
|
||||||
|
@ -82,7 +82,7 @@ export default class Project extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const projectQuery = graphql`
|
export const projectQuery = graphql`
|
||||||
query($slug: String!) {
|
query($slug: String!, $imageRegex: String!) {
|
||||||
projectsYaml(slug: { eq: $slug }) {
|
projectsYaml(slug: { eq: $slug }) {
|
||||||
title
|
title
|
||||||
slug
|
slug
|
||||||
@ -106,7 +106,7 @@ export const projectQuery = graphql`
|
|||||||
}
|
}
|
||||||
|
|
||||||
projectImages: allImageSharp(
|
projectImages: allImageSharp(
|
||||||
filter: { fluid: { originalName: { regex: $slug } } }
|
filter: { fluid: { originalName: { regex: $imageRegex } } }
|
||||||
sort: { fields: [fluid___originalName], order: ASC }
|
sort: { fields: [fluid___originalName], order: ASC }
|
||||||
) {
|
) {
|
||||||
edges {
|
edges {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user