Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.6 #7

Merged
merged 1 commit into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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