Skip to content

Commit

Permalink
fix: current doc seo description
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 12, 2020
1 parent 97441e6 commit 6b01cff
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions core/store/src/Store/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,14 @@ export class Store implements StoryStore {
this._analytics.page();
}
};
getDocDescriotion = (doc: Document): string | undefined => {
getDocDescription = (doc: Document): string | undefined => {
if (doc.description) {
return doc.description;
}
const componentName = getComponentName(doc.component);
if (componentName) {
const component = this.loadedStore?.components[componentName];
const componnetHash = doc.componentsLookup[componentName];
const component = this.loadedStore?.components[componnetHash];
if (component?.info?.description) {
return component.info.description;
}
Expand Down
2 changes: 1 addition & 1 deletion core/store/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface StoryStore {
addObserver: (observer: StoreObserver) => void;
removeObserver: (observer: StoreObserver) => void;
visitPage: () => void;
getDocDescriotion: (doc: Document) => string | undefined;
getDocDescription: (doc: Document) => string | undefined;
}

export const UPDATE_STORY_MSG = 'component_controls_update_story';
Expand Down
3 changes: 1 addition & 2 deletions ui/app/src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ export const App: FC<AppProps> = ({ title = '', children }) => {
const titleParts = title ? title.split('/') : [''];
const pageTitle = titleParts[titleParts.length - 1];
const pageDescription = doc
? storeProvider.getDocDescriotion(doc)
? storeProvider.getDocDescription(doc)
: undefined;
useEffect(() => {
storeProvider.visitPage();
}, [storeProvider]);

return (
<Fragment>
<SEO title={pageTitle} description={pageDescription} />
Expand Down
2 changes: 1 addition & 1 deletion ui/app/src/SEO/SEO.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const SEO = ({
}: SEOProps) => {
const { storeProvider } = useContext(BlockContext);
const config = storeProvider.config;

const {
siteTitle,
siteTitleAlt: defaultTitle,
Expand All @@ -44,6 +43,7 @@ export const SEO = ({
url: `${siteUrl}${pathname || ``}`,
image: `${siteUrl}${image || defaultImage}`,
};
console.log(seo.description);
return (
<Helmet
title={title}
Expand Down
9 changes: 6 additions & 3 deletions ui/blocks/src/context/block/BlockContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ export const BlockContextProvider: React.FC<BlockContextInputProps> = ({
options,
}) => {
let storyId = propsStoryId;
const docId = storyId || propsDocId;
if (!storyId && docId) {
let docId = propsDocId;
if (storyId && !docId) {
const story = store.getStory(storyId);
docId = story?.doc;
} else if (!storyId && docId) {
const doc = store.getStoryDoc(docId);
storyId =
doc && doc.stories && doc.stories.length ? doc.stories[0] : undefined;
Expand All @@ -80,7 +83,7 @@ export const BlockContextProvider: React.FC<BlockContextInputProps> = ({
<BlockContext.Provider
value={{
storyId,
docId: propsDocId,
docId,
storeProvider: store,
options: store.config
? deepMerge(options, store.config)
Expand Down

0 comments on commit 6b01cff

Please sign in to comment.