Skip to content

Commit

Permalink
add search to blog posts
Browse files Browse the repository at this point in the history
  • Loading branch information
tuan2311 committed Aug 12, 2020
1 parent da380cb commit 88adc75
Show file tree
Hide file tree
Showing 16 changed files with 1,309 additions and 192 deletions.
13 changes: 11 additions & 2 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require('dotenv').config();
const { createProxyMiddleware } = require('http-proxy-middleware');
const { queries } = require('./src/utils/algolia');

module.exports = {
siteMetadata: {
Expand Down Expand Up @@ -114,8 +116,15 @@ module.exports = {
icon: `src/images/favicon.ico`,
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
`gatsby-plugin-offline`,
{
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_KEY,
queries,
chunkSize: 10000, // default: 1000
},
},
],
};
16 changes: 15 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require('dotenv').config();
const path = require('path');
const { merge } = require('webpack-merge');
const { fmImagesToRelative } = require('gatsby-remark-relative-images');

const postsPerPage = 6;

exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
exports.onCreateWebpackConfig = ({ actions, getConfig, plugins }) => {
let config = getConfig();
config.module.rules = config.module.rules.map((item) => {
const { test } = item;
Expand All @@ -27,6 +28,19 @@ exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
'~': path.resolve(__dirname, 'src'),
},
},
plugins: [
plugins.define(
[
'GATSBY_ALGOLIA_SEARCH_KEY',
'GATSBY_ALGOLIA_APP_ID',
'ALGOLIA_INDEX_NAME',
].reduce((agg, current) => ({
...agg,
[`process.env.${current}`]: JSON.stringify(process.env[current]),
})),
{}
),
],
module: {
rules: [
{
Expand Down
Loading

0 comments on commit 88adc75

Please sign in to comment.