Skip to content

Commit

Permalink
fix: add ogtags to sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Krysiak authored and Wojciech Krysiak committed Sep 7, 2020
1 parent 54bd0c8 commit b5b8305
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 4 additions & 1 deletion fixtures/sections-json/sections.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"title": "First"
},
"designsystem": {
"title": "Design System"
"title": "Design System",
"ogTags": {
"title": "title from section"
}
}
}
1 change: 1 addition & 0 deletions publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ exports.publish = function (taffyData, opts, tutorials) {
readme,
subtitle: '',
sections: decoratedSections,
docs: [section],
}

view.layout = 'layout.tmpl'
Expand Down
25 changes: 20 additions & 5 deletions src/better-docs.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ export type NavLink = {

export type OgTags = {
/**
* Default value for @ogTitle tag
* Value for @ogTitle tag
*/
title?: string;
/**
* Default value for @ogDescription tags
* Value for @ogDescription tag
*/
description: string;
description?: string;
/**
* Default value for @ogImage tags
* Value for @ogImage tag
*/
image: string;
image?: string;
/**
* Value for @ogLocale tag
*/
locale?: string;
/**
* Value for @ogUrl tag
*/
url?: string;
/**
* Value for @ogType tag
*/
type?: string;
}

export type BetterDocsConfig = {
Expand All @@ -39,6 +51,9 @@ export type BetterDocsConfig = {
* Page Title
*/
title?: string;
/**
* Default OgTags
*/
ogTags: OgTags;
/**
* Component config
Expand Down
11 changes: 10 additions & 1 deletion src/sections/decorate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import { OgTags } from '../better-docs.type'

export const SECTIONS_CONFIG_FILE_NAME = 'sections.json'

Expand All @@ -16,6 +17,7 @@ export type SectionNav = {
export type SectionsJSON = {
[name: string]: {
title: string;
ogTags: OgTags;
};
}

Expand Down Expand Up @@ -54,6 +56,7 @@ export type SectionConfig = {
title?: string;
homePath?: string;
homeBody?: string;
ogTags?: OgTags;
}

/**
Expand Down Expand Up @@ -89,14 +92,15 @@ const loadConfig = (sectionConfigPath?: string): Record<string, SectionConfig> |
return files.filter(file => path.parse(file).ext === '.md').reduce((memo, file) => {
const name = buildKey(path.parse(file).name)
const config = jsonConfig[name]
const { title } = config || {}
const { title, ogTags } = config || {}
const homePath = path.join(sectionConfigPath, file)
const homeBody = fs.readFileSync(homePath, 'utf8')

return {
...memo,
[name]: {
title,
ogTags,
homePath,
homeBody,
},
Expand Down Expand Up @@ -131,9 +135,13 @@ export function decorateSections(

// on which place should it go to navigation. By default some big number
let order = 1000 + index
let ogTags

if (configSection) {
href = buildFileName(sectionName)
// eslint-disable-next-line prefer-destructuring
ogTags = configSection.ogTags

if (configSection.title) {
({ title } = configSection)
}
Expand All @@ -149,6 +157,7 @@ export function decorateSections(
title,
href,
order,
ogTags,
homeBody: configSection?.homeBody,
homePath: configSection?.homePath,
},
Expand Down

0 comments on commit b5b8305

Please sign in to comment.