From 4f442afa0b6a29e2cc967d292f24160966aac21d Mon Sep 17 00:00:00 2001 From: Liam Martens Date: Sat, 11 Jan 2020 00:20:57 +0100 Subject: [PATCH] v1.0.6 Allow dynamic baseUrl --- README.md | 3 +++ package.json | 2 +- src/input/index.tsx | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1da6563..cfa336b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ export default { type: 'seo-tools', // use seo-tools type options: { baseUrl: 'https://.../', // (REQUIRED) This is the baseUrl for your site + baseUrl(doc) { + return 'https://.../'; // for dynamic baseUrls + }, slug(doc) { // (REQUIRED) a function to return the sug of the current page, which will be appended to the baseUrl return doc.slug.current; }, diff --git a/package.json b/package.json index 2ad37f0..2cda071 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sanity-plugin-seo-tools", - "version": "1.0.5", + "version": "1.0.6", "license": "GPL-3.0", "author": { "name": "Liam Martens", diff --git a/src/input/index.tsx b/src/input/index.tsx index be7d570..0784252 100644 --- a/src/input/index.tsx +++ b/src/input/index.tsx @@ -20,7 +20,7 @@ enum Tabs { } interface IOptions { - baseUrl: string; + baseUrl: string | ((doc: any) => string); slug: (doc: any) => string; fetchRemote?: boolean; content?: (doc: any) => string; @@ -219,7 +219,10 @@ class InputContainer extends React.PureComponent { return new Promise(async (res, rej) => { const { type, document } = this.props; const { options } = type; - const baseUrl = options.baseUrl.replace(/\/+$/, ''); + const baseUrl = (() => { + const url = typeof options.baseUrl === 'string' ? options.baseUrl : options.baseUrl(document); + return url.replace(/\/+$/, ''); + })(); const slug = options.slug(document); const url = baseUrl + '/' + slug;