Browse Source

fix: more clean up, bundle size

fix/enable-imgix
Thomas Osmonson 4 years ago
parent
commit
9cc0ddd92c
  1. 6
      babel.config.js
  2. 2
      next.config.js
  3. 0
      src/_data/appFAQ.json
  4. 0
      src/_data/clarityRef.json
  5. 0
      src/_data/cliRef.js
  6. 0
      src/_data/faqs.json
  7. 0
      src/_data/glossary.csv
  8. 0
      src/_includes/architecture.md
  9. 0
      src/_includes/contribute_code.md
  10. 0
      src/_includes/contribute_community.md
  11. 0
      src/_includes/contribute_issues.md
  12. 0
      src/_includes/contribute_ovr.md
  13. 0
      src/_includes/create_id.md
  14. 0
      src/_includes/mining-ranking.md
  15. 0
      src/_includes/required-fields.md
  16. 0
      src/_includes/scaffolding.md
  17. 0
      src/_includes/sign_in.md
  18. 28
      src/common/data/clarity-ref.ts
  19. 11
      src/common/data/cli-ref.ts
  20. 26
      src/common/data/faq.ts
  21. 8
      src/common/data/glossary.ts
  22. 17
      src/common/data/mdx.ts
  23. 78
      src/common/mdx.ts
  24. 2
      src/common/routes/get-routes.js
  25. 2
      src/components/cli-reference.tsx
  26. 29
      src/components/code-block/index.tsx
  27. 36
      src/components/feedback.tsx
  28. 1
      src/components/footer.tsx
  29. 7
      src/components/home/sections/hero.tsx
  30. 26
      src/components/mdx/components.tsx
  31. 2
      src/pages/core/cmdLineRef.md
  32. 2
      src/pages/core/faq_developer.md
  33. 2
      src/pages/core/faq_technical.md
  34. 2
      src/pages/core/smart/clarityRef.md
  35. 2
      src/pages/faqs/allFAQS.md
  36. 2
      src/pages/org/faq.md
  37. 2
      src/pages/org/terms.md
  38. 2
      src/pages/org/wallet-troubleshoot.md

6
babel.config.js

@ -3,12 +3,6 @@ module.exports = {
plugins: [
'./lib/babel-plugin-nextjs-mdx-patch',
'babel-plugin-macros',
[
'prismjs',
{
languages: ['bash', 'css', 'jsx', 'tsx', 'json', 'toml', 'python', 'kotlin', 'nginx'],
},
],
['styled-components', { ssr: true }],
],
};

2
next.config.js

@ -7,7 +7,7 @@ const path = require('path');
const remarkPlugins = [
[
require('@hashicorp/remark-plugins').includeMarkdown,
{ resolveFrom: path.join(__dirname, 'src/common/_includes') },
{ resolveFrom: path.join(__dirname, 'src/_includes') },
],
require('remark-squeeze-paragraphs'),
require('./lib/remark-paragraph-alerts'),

0
src/common/_data/appFAQ.json → src/_data/appFAQ.json

0
src/common/_data/clarityRef.json → src/_data/clarityRef.json

0
src/common/_data/cliRef.js → src/_data/cliRef.js

0
src/common/_data/faqs.json → src/_data/faqs.json

0
src/common/_data/glossary.csv → src/_data/glossary.csv

Can't render this file because it contains an unexpected character in line 15 and column 0.

0
src/common/_includes/architecture.md → src/_includes/architecture.md

0
src/common/_includes/contribute_code.md → src/_includes/contribute_code.md

0
src/common/_includes/contribute_community.md → src/_includes/contribute_community.md

0
src/common/_includes/contribute_issues.md → src/_includes/contribute_issues.md

0
src/common/_includes/contribute_ovr.md → src/_includes/contribute_ovr.md

0
src/common/_includes/create_id.md → src/_includes/create_id.md

0
src/common/_includes/mining-ranking.md → src/_includes/mining-ranking.md

0
src/common/_includes/required-fields.md → src/_includes/required-fields.md

0
src/common/_includes/scaffolding.md → src/_includes/scaffolding.md

0
src/common/_includes/sign_in.md → src/_includes/sign_in.md

28
src/common/data/clarity-ref.ts

@ -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,
},
},
};
};

11
src/common/data/cli-ref.ts

@ -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,
},
};
};

26
src/common/data/faq.ts

@ -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,
},
};
};

8
src/common/glossary.ts → src/common/data/glossary.ts

@ -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 => ({

17
src/common/data/mdx.ts

@ -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 })));

78
src/common/mdx.ts

@ -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,
},
},
};
};

2
src/common/routes/get-routes.js

@ -139,7 +139,6 @@ const getHeadings = mdContent => {
const routes = sections.map(section => {
const _routes = section.routes.map(route => {
try {
const extension = /\.(mdx?)$/;
const fileContent = fs.readFileSync(path.join('./src/pages/', route.path + '.md'), 'utf8');
const data = fm(fileContent);
const headings = getHeadings(data.body);
@ -155,7 +154,6 @@ const routes = sections.map(section => {
return {
...section,
routes: _routes,
directory: process.cwd(),
};
});

2
src/components/cli-reference.tsx

@ -1,5 +1,5 @@
import React from 'react';
import { cliReferenceData } from '@common/_data/cliRef';
import { cliReferenceData } from '@common/../_data/cliRef';
import { MDXComponents } from '@components/mdx/mdx-components';
import { Grid, Box } from '@blockstack/ui';
import { border } from '@common/utils';

29
src/components/code-block/index.tsx

@ -11,19 +11,24 @@ import 'prismjs/components/prism-kotlin';
import { SimpleCodeBlock } from '@components/code-block/components';
import { useForceUpdate } from '@blockstack/ui';
export const CodeBlock = ({ className, live = true, isManual, render, children, ...props }) => {
const update = useForceUpdate();
React.useEffect(() => {
update();
}, []);
export const CodeBlock = React.memo(
({ className, live = true, isManual, render, children, ...props }: any) => {
const update = useForceUpdate();
React.useEffect(() => {
update();
}, []);
const language = className && className.replace(/language-/, '');
const language = className && className.replace(/language-/, '');
return <SimpleCodeBlock editorCode={children.toString()} language={language} {...props} />;
};
CodeBlock.defaultProps = {
mountStylesheet: false,
};
return (
<SimpleCodeBlock
editorCode={children.toString()}
showLineNumbers={language !== 'bash'}
language={language}
{...props}
/>
);
}
);
export default CodeBlock;

36
src/components/feedback.tsx

@ -1,9 +1,10 @@
import React from 'react';
import { Box, BoxProps, color, Flex, space, Stack, themeColor } from '@blockstack/ui';
import { MDXComponents } from '@components/mdx';
import { MDXComponents, Link } from '@components/mdx';
import { SadIcon, NeutralIcon, HappyIcon } from '@components/icons/feedback';
import { useHover } from 'use-events';
import { border } from '@common/utils';
import { useRouter } from 'next/router';
const Icon: React.FC<BoxProps & { icon: React.FC<any> }> = ({ icon: IconComponent, ...props }) => {
const [isHovered, bind] = useHover();
@ -15,14 +16,31 @@ const Icon: React.FC<BoxProps & { icon: React.FC<any> }> = ({ icon: IconComponen
};
export const FeedbackSection: React.FC<BoxProps> = props => {
const { pathname } = useRouter();
return (
<Box borderTop={border()} mt={space('extra-loose')}>
<MDXComponents.h3>Was this page helpful?</MDXComponents.h3>
<Stack isInline spacing={space('base-loose')} mt={space('base-loose')}>
<Icon icon={SadIcon} />
<Icon icon={NeutralIcon} />
<Icon icon={HappyIcon} />
</Stack>
</Box>
<Flex
flexDirection={['column', 'column', 'row']}
justifyContent="space-between"
borderTop={border()}
mt={space('extra-loose')}
>
<Box>
<MDXComponents.h3>Was this page helpful?</MDXComponents.h3>
<Stack isInline spacing={space('base-loose')} mt={space('base-loose')}>
<Icon icon={SadIcon} />
<Icon icon={NeutralIcon} />
<Icon icon={HappyIcon} />
</Stack>
</Box>
<Box mt={space(['extra-loose', 'extra-loose', 'base-loose'])}>
<Link
href={`https://github.com/blockstack/docs.blockstack/tree/feat/next/src/pages${pathname}.md`}
target="_blank"
rel="nofollow noopener noreferrer"
>
Edit this page on GitHub
</Link>
</Box>
</Flex>
);
};

1
src/components/footer.tsx

@ -3,6 +3,7 @@ import { Pagination } from '@components/pagination';
import { Section, SectionWrapper } from '@components/home/common';
import { FeedbackSection } from '@components/feedback';
const Footer = ({ hidePagination, ...rest }: any) => {
return (
<Section>

7
src/components/home/sections/hero.tsx

@ -22,7 +22,12 @@ export const Hero = ({ cards }: { cards?: any }) => {
width="100%"
gridGap={space('extra-loose')}
minHeight="200px"
gridTemplateColumns={['repeat(1, 1fr)', 'repeat(2, 1fr)', 'repeat(3, 1fr)']}
gridTemplateColumns={[
'repeat(1, 1fr)',
'repeat(1, 1fr)',
'repeat(2, 1fr)',
'repeat(3, 1fr)',
]}
mx="auto"
mt={space('extra-loose')}
px={space('extra-loose')}

26
src/components/mdx/components.tsx

@ -91,18 +91,20 @@ export const TData = (props: any) => (
/>
);
export const Link = forwardRef((props: { href: string } & BoxProps, ref: Ref<HTMLDivElement>) => (
<Box
as="a"
ref={ref}
color="var(--colors-accent)"
cursor="pointer"
textDecoration="underline"
_hover={{ textDecoration: 'none' }}
_focus={{ boxShadow: 'outline' }}
{...props}
/>
));
export const Link = forwardRef(
(props: { href: string; target?: string; rel?: string } & BoxProps, ref: Ref<HTMLDivElement>) => (
<Box
as="a"
ref={ref}
color="var(--colors-accent)"
cursor="pointer"
textDecoration="underline"
_hover={{ textDecoration: 'none' }}
_focus={{ boxShadow: 'outline' }}
{...props}
/>
)
);
export const TextItem = (props: any) => (
<Text

2
src/pages/core/cmdLineRef.md

@ -2,7 +2,7 @@
title: Blockstack CLI Reference
---
export { convertBlockstackCLIUsageToMdx as getStaticProps } from '@common/mdx'
export { convertBlockstackCLIUsageToMdx as getStaticProps } from '@common/data/cli-ref'
import { CLIReferenceTable } from '@components/cli-reference'
# Blockstack CLI reference

2
src/pages/core/faq_developer.md

@ -2,7 +2,7 @@
description: Blockstack DApp technical FAQs
---
export { convertFaqAnswersToMDX as getStaticProps } from '@common/mdx'
export { convertFaqAnswersToMDX as getStaticProps } from '@common/data/faq'
import { FAQs } from '@components/faq'
# DApp Developer FAQs

2
src/pages/core/faq_technical.md

@ -1,4 +1,4 @@
export { convertFaqAnswersToMDX as getStaticProps } from '@common/mdx'
export { convertFaqAnswersToMDX as getStaticProps } from '@common/data/faq'
import { FAQs } from '@components/faq'
# Technical FAQ

2
src/pages/core/smart/clarityRef.md

@ -2,7 +2,7 @@
description: 'See a detailed list of all keywords and functions for the Clarity language.'
---
export { convertClarityRefUsageToMdx as getStaticProps } from '@common/mdx'
export { convertClarityRefUsageToMdx as getStaticProps } from '@common/data/clarity-ref'
import { ClarityKeywordReference, ClarityFunctionReference } from '@components/clarity-ref'
# Clarity Language Reference

2
src/pages/faqs/allFAQS.md

@ -4,7 +4,7 @@ description: 'Blockstack Network documentation'
redirect_from: /org/voucherholder
---
export { convertFaqAnswersToMDX as getStaticProps } from '@common/mdx'
export { convertFaqAnswersToMDX as getStaticProps } from '@common/data/faq'
import { FAQs } from '@components/faq'
# Blockstack FAQs

2
src/pages/org/faq.md

@ -2,7 +2,7 @@
description: 'Blockstack Network documentation'
---
export { convertFaqAnswersToMDX as getStaticProps } from '@common/mdx'
export { convertFaqAnswersToMDX as getStaticProps } from '@common/data/faq'
import { FAQs } from '@components/faq'
# FAQs about Stacks tokens and wallet

2
src/pages/org/terms.md

@ -2,7 +2,7 @@
description: 'Blockstack Network documentation'
---
export { convertGlossaryToJson as getStaticProps } from '@common/glossary'
export { convertGlossaryToJson as getStaticProps } from '@common/data/glossary'
import { Glossary } from '@components/glossary'
# Glossary

2
src/pages/org/wallet-troubleshoot.md

@ -2,7 +2,7 @@
description: 'How to use the Blockstack Software'
---
export { convertFaqAnswersToMDX as getStaticProps } from '@common/mdx'
export { convertFaqAnswersToMDX as getStaticProps } from '@common/data/faq'
import { FAQs } from '@components/faq'
<!-- TODO: very out of date, update content -->

Loading…
Cancel
Save