mirror of https://github.com/lukechilds/docs.git
Thomas Osmonson
4 years ago
38 changed files with 162 additions and 133 deletions
Can't render this file because it contains an unexpected character in line 15 and column 0.
|
@ -0,0 +1,28 @@ |
|||
import { convertRemoteDataToMDX } from '@common/data/mdx'; |
|||
import CLARITY_REFERENCE from '../../_data/clarityRef.json'; |
|||
|
|||
export const convertClarityRefUsageToMdx = async () => { |
|||
const [_functions, _keywords] = await Promise.all([ |
|||
convertRemoteDataToMDX(CLARITY_REFERENCE.functions, 'description'), |
|||
convertRemoteDataToMDX(CLARITY_REFERENCE.keywords, 'description'), |
|||
]); |
|||
|
|||
const functions = CLARITY_REFERENCE.functions.map((fn, index) => ({ |
|||
...fn, |
|||
description: _functions[index], |
|||
})); |
|||
|
|||
const keywords = CLARITY_REFERENCE.keywords.map((fn, index) => ({ |
|||
...fn, |
|||
description: _keywords[index], |
|||
})); |
|||
|
|||
return { |
|||
props: { |
|||
mdx: { |
|||
functions, |
|||
keywords, |
|||
}, |
|||
}, |
|||
}; |
|||
}; |
@ -0,0 +1,11 @@ |
|||
import { convertRemoteDataToMDX } from '@common/data/mdx'; |
|||
import { cliReferenceData } from '../../_data/cliRef'; |
|||
|
|||
export const convertBlockstackCLIUsageToMdx = async () => { |
|||
const results = await convertRemoteDataToMDX(cliReferenceData, 'usage'); |
|||
return { |
|||
props: { |
|||
mdx: results, |
|||
}, |
|||
}; |
|||
}; |
@ -0,0 +1,26 @@ |
|||
import { convertRemoteDataToMDX } from '@common/data/mdx'; |
|||
|
|||
import FAQ_JSON from '../../_data/faqs.json'; |
|||
import TurndownService from 'turndown'; |
|||
|
|||
export const convertFaqAnswersToMDX = async () => { |
|||
const turndownService = new TurndownService(); |
|||
// we convert html to markdown so we can process it with remark,
|
|||
// eg external links open in new window
|
|||
const md = FAQ_JSON.faqs.map(faq => ({ |
|||
...faq, |
|||
answer: turndownService.turndown(faq.answer), |
|||
})); |
|||
// convert it to MDX with next-mdx-remote
|
|||
const answers = await convertRemoteDataToMDX(md, 'answer'); |
|||
const faqs = FAQ_JSON.faqs.map((faq, index) => ({ |
|||
...faq, |
|||
answer: answers[index], |
|||
})); |
|||
|
|||
return { |
|||
props: { |
|||
mdx: faqs, |
|||
}, |
|||
}; |
|||
}; |
@ -1,16 +1,18 @@ |
|||
const csv = require('csvtojson'); |
|||
import csv from 'csvtojson'; |
|||
import TurndownService from 'turndown'; |
|||
import { convertRemoteDataToMDX } from '@common/mdx'; |
|||
import { convertRemoteDataToMDX } from '@common/data/mdx'; |
|||
|
|||
export const convertGlossaryToJson = async () => { |
|||
const turndownService = new TurndownService(); |
|||
const data = await csv().fromFile('./src/common/_data/glossary.csv'); |
|||
// convert csv to json
|
|||
const data = await csv().fromFile('./src/_data/glossary.csv'); |
|||
const formatted = data |
|||
.filter(entry => entry.Term !== '') |
|||
.map(entry => ({ |
|||
term: entry['Term'], |
|||
definition: entry['Definition'], |
|||
})); |
|||
|
|||
// we convert html to markdown so we can process it with remark,
|
|||
// eg external links open in new window
|
|||
const md = formatted.map(entry => ({ |
@ -0,0 +1,17 @@ |
|||
import { MDXComponents } from '@components/mdx/mdx-components'; |
|||
import renderToString from 'next-mdx-remote/render-to-string'; |
|||
|
|||
const remarkPlugins = [ |
|||
require('remark-squeeze-paragraphs'), |
|||
require('remark-external-links'), |
|||
require('remark-emoji'), |
|||
require('remark-images'), |
|||
require('remark-unwrap-images'), |
|||
require('remark-normalize-headings'), |
|||
require('remark-slug'), |
|||
]; |
|||
|
|||
export const wrapValueInTicks = value => '`' + value.replace('`', '').replace('`', '') + '`'; |
|||
|
|||
export const convertRemoteDataToMDX = async (arr: any[], key: string) => |
|||
Promise.all(arr.map(entry => renderToString(entry[key], MDXComponents, { remarkPlugins }))); |
@ -1,78 +0,0 @@ |
|||
import { MDXComponents } from '@components/mdx/mdx-components'; |
|||
import { cliReferenceData } from '@common/_data/cliRef'; |
|||
import renderToString from 'next-mdx-remote/render-to-string'; |
|||
import CLARITY_REFERENCE from '@common/_data/clarityRef.json'; |
|||
import FAQ_JSON from '@common/_data/faqs.json'; |
|||
import TurndownService from 'turndown'; |
|||
|
|||
const remarkPlugins = [ |
|||
require('remark-squeeze-paragraphs'), |
|||
require('remark-external-links'), |
|||
require('remark-emoji'), |
|||
require('remark-images'), |
|||
require('remark-unwrap-images'), |
|||
require('remark-normalize-headings'), |
|||
require('remark-slug'), |
|||
]; |
|||
|
|||
export const wrapValueInTicks = value => '`' + value.replace('`', '').replace('`', '') + '`'; |
|||
|
|||
export const convertRemoteDataToMDX = async (arr: any[], key: string) => |
|||
Promise.all(arr.map(entry => renderToString(entry[key], MDXComponents, { remarkPlugins }))); |
|||
|
|||
export const convertFaqAnswersToMDX = async () => { |
|||
const turndownService = new TurndownService(); |
|||
// we convert html to markdown so we can process it with remark,
|
|||
// eg external links open in new window
|
|||
const md = FAQ_JSON.faqs.map(faq => ({ |
|||
...faq, |
|||
answer: turndownService.turndown(faq.answer), |
|||
})); |
|||
// convert it to MDX with next-mdx-remote
|
|||
const answers = await convertRemoteDataToMDX(md, 'answer'); |
|||
const faqs = FAQ_JSON.faqs.map((faq, index) => ({ |
|||
...faq, |
|||
answer: answers[index], |
|||
})); |
|||
|
|||
return { |
|||
props: { |
|||
mdx: faqs, |
|||
}, |
|||
}; |
|||
}; |
|||
|
|||
export const convertBlockstackCLIUsageToMdx = async () => { |
|||
const results = await convertRemoteDataToMDX(cliReferenceData, 'usage'); |
|||
return { |
|||
props: { |
|||
mdx: results, |
|||
}, |
|||
}; |
|||
}; |
|||
|
|||
export const convertClarityRefUsageToMdx = async () => { |
|||
const [_functions, _keywords] = await Promise.all([ |
|||
convertRemoteDataToMDX(CLARITY_REFERENCE.functions, 'description'), |
|||
convertRemoteDataToMDX(CLARITY_REFERENCE.keywords, 'description'), |
|||
]); |
|||
|
|||
const functions = CLARITY_REFERENCE.functions.map((fn, index) => ({ |
|||
...fn, |
|||
description: _functions[index], |
|||
})); |
|||
|
|||
const keywords = CLARITY_REFERENCE.keywords.map((fn, index) => ({ |
|||
...fn, |
|||
description: _keywords[index], |
|||
})); |
|||
|
|||
return { |
|||
props: { |
|||
mdx: { |
|||
functions, |
|||
keywords, |
|||
}, |
|||
}, |
|||
}; |
|||
}; |
Loading…
Reference in new issue