Skip to content

Commit

Permalink
Merge pull request #7 from LiamMartens/feature/dynamic-baseurl
Browse files Browse the repository at this point in the history
v1.0.6 Dynamic baseUrl
  • Loading branch information
LiamMartens authored Jan 10, 2020
2 parents 551e9b9 + 4f442af commit d922b25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -219,7 +219,10 @@ class InputContainer extends React.PureComponent<IProps, IState> {
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;

Expand Down

0 comments on commit d922b25

Please sign in to comment.