-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4927 from reactioncommerce/feat-4796-impactmass-s…
…itemap-query feat: Make Sitemap data available via GraphQL query
- Loading branch information
Showing
8 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
imports/plugins/included/sitemap-generator/server/no-meteor/resolvers/Query/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sitemap from "./sitemap"; | ||
|
||
export default { | ||
sitemap | ||
}; |
31 changes: 31 additions & 0 deletions
31
imports/plugins/included/sitemap-generator/server/no-meteor/resolvers/Query/sitemap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import url from "url"; | ||
|
||
/** | ||
* @name sitemapQuery | ||
* @method | ||
* @param {Object} _ - unused | ||
* @param {Object} params - an object of all arguments that were sent by the client | ||
* @param {String} params.handle - Sitemap's handle, as set in Sitemaps collection | ||
* @param {String} params.shopUrl - URL of the shop the sitemap belongs to. The URL is used to find the shop with the domain of the URL | ||
* @param {Object} context - an object containing the per-request state | ||
* @returns {String} - Sitemap object containing XML with placeholders replaced (BASE_URL, LAST_MOD) | ||
*/ | ||
export default async function sitemapQuery(_, params, context) { | ||
const { Sitemaps, Shops } = context.collections; | ||
const { handle, shopUrl } = params; | ||
|
||
const domain = url.parse(shopUrl).hostname; | ||
|
||
// ensure the domain requested is for a known shop domain | ||
const { _id: shopId } = await Shops.findOne({ domains: domain }) || {}; | ||
|
||
if (!shopId) return null; | ||
|
||
const sitemap = await Sitemaps.findOne({ shopId, handle }); | ||
|
||
if (!sitemap) return null; | ||
|
||
sitemap.xml = sitemap.xml.replace(/BASE_URL/g, shopUrl); | ||
|
||
return sitemap; | ||
} |
5 changes: 5 additions & 0 deletions
5
imports/plugins/included/sitemap-generator/server/no-meteor/resolvers/Sitemap/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { encodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop"; | ||
|
||
export default { | ||
shopId: (node) => encodeShopOpaqueId(node.shopId) | ||
}; |
6 changes: 5 additions & 1 deletion
6
imports/plugins/included/sitemap-generator/server/no-meteor/resolvers/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import Mutation from "./Mutation"; | ||
import Query from "./Query"; | ||
import Sitemap from "./Sitemap"; | ||
|
||
export default { | ||
Mutation | ||
Mutation, | ||
Query, | ||
Sitemap | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
imports/plugins/included/sitemap-generator/server/no-meteor/startup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @summary Called on startup | ||
* @param {Object} context Startup context | ||
* @returns {undefined} | ||
*/ | ||
export default function startup(context) { | ||
context.collections.Sitemaps = context.app.db.collection("Sitemaps"); | ||
} |