Browse Source

feat: added new support for translation of docs

subfolderRevert
Jonathon 3 years ago
committed by Friedger Müffke
parent
commit
864ccc42f3
  1. 2
      .eslintrc.js
  2. 1
      lib/rehype-image-size.js
  3. 13
      lib/remark-custom-blocks.js
  4. 8
      lib/remark-include.js
  5. 5
      next-env.d.ts
  6. 20
      next.config.js
  7. 2
      package.json
  8. 2
      src/common/constants.ts
  9. 2
      src/common/data/mdx.ts
  10. 6
      src/common/routes/get-routes.js
  11. 2
      src/components/status-check.tsx
  12. 0
      src/pages/404/index.md
  13. 18
      src/pages/_middleware.tsx
  14. 0
      src/pages/api/status/index.js
  15. 0
      src/pages/build-apps/overview/index.md
  16. 0
      src/pages/build-apps/references/authentication/index.md
  17. 0
      src/pages/build-apps/references/bns/index.md
  18. 0
      src/pages/build-apps/references/gaia/index.md
  19. 0
      src/pages/contributing/index.md
  20. 21
      src/pages/index/index.md
  21. 0
      src/pages/references/bns-contract/index.md
  22. 0
      src/pages/references/deploy-tips/index.md
  23. 0
      src/pages/references/faqs/index.md
  24. 0
      src/pages/references/glossary/index.md
  25. 0
      src/pages/references/language-functions/index.md
  26. 0
      src/pages/references/language-keywords/index.md
  27. 0
      src/pages/references/language-overview/index.md
  28. 0
      src/pages/references/language-types/index.md
  29. 0
      src/pages/references/stacking-contract/index.md
  30. 0
      src/pages/references/stacks-node-configuration/index.md
  31. 0
      src/pages/start-mining/mainnet/index.md
  32. 0
      src/pages/start-mining/testnet/index.md
  33. 0
      src/pages/understand-stacks/accounts/index.md
  34. 0
      src/pages/understand-stacks/microblocks/index.md
  35. 0
      src/pages/understand-stacks/mining/index.md
  36. 0
      src/pages/understand-stacks/network/index.md
  37. 0
      src/pages/understand-stacks/overview/index.md
  38. 0
      src/pages/understand-stacks/proof-of-transfer/index.md
  39. 0
      src/pages/understand-stacks/running-mainnet-node/index.md
  40. 0
      src/pages/understand-stacks/running-testnet-node/index.md
  41. 0
      src/pages/understand-stacks/stacking/index.md
  42. 0
      src/pages/understand-stacks/stacks-blockchain-api/index.md
  43. 0
      src/pages/understand-stacks/technical-specs/index.md
  44. 0
      src/pages/understand-stacks/testnet/index.md
  45. 0
      src/pages/understand-stacks/transactions/index.md
  46. 0
      src/pages/write-smart-contracts/overview/index.md
  47. 0
      src/pages/write-smart-contracts/principals/index.md
  48. 0
      src/pages/write-smart-contracts/tokens/index.md
  49. 0
      src/pages/write-smart-contracts/values/index.md
  50. 3065
      yarn.lock

2
.eslintrc.js

@ -25,5 +25,7 @@ module.exports = {
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/restrict-template-expressions': 0,
'@typescript-eslint/require-await': 0,
'@typescript-eslint/no-var-requires': 0,
},
};

1
lib/rehype-image-size.js

@ -22,6 +22,7 @@ const rehypeImageSize = () => {
);
return tree;
}
async function visitor(node) {
const isRelative =
node && node.properties && node.properties.src && node.properties.src.startsWith('/');

13
lib/remark-custom-blocks.js

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unbound-method */
const spaceSeparated = require('space-separated-tokens');
function escapeRegExp(str) {
@ -135,10 +136,11 @@ module.exports = function blockPlugin(availableBlocks = {}) {
const Parser = this.Parser;
// Inject blockTokenizer
const newLocal = 'customBlocks';
const blockTokenizers = Parser.prototype.blockTokenizers;
const blockMethods = Parser.prototype.blockMethods;
blockTokenizers.customBlocks = blockTokenizer;
blockMethods.splice(blockMethods.indexOf('fencedCode') + 1, 0, 'customBlocks');
blockMethods.splice(parseInt(blockMethods.indexOf(newLocal)) + 1, 0, 'customBlocks');
const Compiler = this.Compiler;
if (Compiler) {
const visitors = Compiler.prototype.visitors;
@ -154,7 +156,10 @@ module.exports = function blockPlugin(availableBlocks = {}) {
const interruptParagraph = Parser.prototype.interruptParagraph;
const interruptList = Parser.prototype.interruptList;
const interruptBlockquote = Parser.prototype.interruptBlockquote;
interruptParagraph.splice(interruptParagraph.indexOf('fencedCode') + 1, 0, ['customBlocks']);
interruptList.splice(interruptList.indexOf('fencedCode') + 1, 0, ['customBlocks']);
interruptBlockquote.splice(interruptBlockquote.indexOf('fencedCode') + 1, 0, ['customBlocks']);
interruptParagraph.splice(parseInt(interruptParagraph.indexOf('fencedCode')) + 1, 0, [newLocal]);
interruptList.splice(parseInt(interruptList.indexOf('fencedCode')) + 1, 0, ['customBlocks']);
interruptBlockquote.splice(parseInt(interruptBlockquote.indexOf('fencedCode')) + 1, 0, [
'customBlocks',
]);
};

8
lib/remark-include.js

@ -25,9 +25,11 @@ module.exports = function includeMarkdownPlugin({ resolveFrom } = {}) {
);
}
const mdregex = /\.md(?:x)?$/;
// if we are including a ".md" or ".mdx" file, we add the contents as processed markdown
// if any other file type, they are embedded into a code block
if (includePath.match(/\.md(?:x)?$/)) {
// eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
if (includePath.match(mdregex)) {
// return the file contents in place of the @include
// this takes a couple steps because we allow recursive includes
const processor = remark().use(includeMarkdownPlugin, { resolveFrom });
@ -37,11 +39,13 @@ module.exports = function includeMarkdownPlugin({ resolveFrom } = {}) {
// trim trailing newline
includeContents.contents = includeContents.contents.trim();
const codecheckregex = /\.(\w+)$/;
// return contents wrapped inside a "code" node
return [
{
type: 'code',
lang: includePath.match(/\.(\w+)$/)[1],
// eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
lang: includePath.match(codecheckregex)[1],
value: includeContents,
},
];

5
next-env.d.ts

@ -1,2 +1,5 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

20
next.config.js

@ -937,10 +937,6 @@ async function redirects() {
module.exports = withFonts(
withBundleAnalyzer({
i18n: {
locales: ['en-US'],
defaultLocale: 'en-US',
},
experimental: {
modern: true,
polyfillsOptimization: true,
@ -979,17 +975,19 @@ module.exports = withFonts(
if (splitChunks) {
const cacheGroups = splitChunks.cacheGroups;
const test = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/;
if (cacheGroups.framework) {
cacheGroups.preact = Object.assign({}, cacheGroups.framework, {
if (cacheGroups?.framework) {
cacheGroups.preact = Object.assign({}, cacheGroups?.framework, {
test,
});
cacheGroups.commons.name = 'framework';
} else {
cacheGroups.preact = {
name: 'commons',
chunks: 'all',
test,
};
if (typeof cacheGroups !== 'undefined') {
cacheGroups.preact = {
name: 'commons',
chunks: 'all',
test,
};
}
}
}

2
package.json

@ -51,7 +51,7 @@
"mdi-react": "7.4.0",
"micro-memoize": "^4.0.9",
"modern-normalize": "^1.0.0",
"next": "^10.0.5",
"next": "12",
"next-fonts": "^1.4.0",
"next-mdx-remote": "^1.0.0",
"nprogress": "^0.2.0",

2
src/common/constants.ts

@ -6,3 +6,5 @@ export const SHIKI_THEME = 'Material-Theme-Default';
export const THEME_STORAGE_KEY = 'theme';
export const STATUS_CHECKER_URL = 'https://status.test-blockstack.com';
export const SUPPORTED_LANGUAGES = ['en'];

2
src/common/data/mdx.ts

@ -1,9 +1,7 @@
import { Components } from '@components/mdx/mdx-components';
import renderToString from 'next-mdx-remote/render-to-string';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { remarkPlugins } = require('../../../lib/remark-plugins');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { rehypePlugins } = require('../../../lib/rehype-plugins');
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands

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

@ -8,6 +8,7 @@
* This data is used to dynamically generate the sidenav.
*
*/
const fm = require('front-matter');
const fs = require('fs-extra');
const path = require('path');
@ -46,6 +47,7 @@ const getFlatMap = navigation => {
});
return [...pages, ...sectionPages];
} else {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
return `${section.title ? '/' + slugify(section.title) : ''}${page.path}`;
}
})
@ -63,9 +65,11 @@ const getHeadings = mdContent => {
};
const routes = allRoutes.map(route => {
// detect the locale
// index.${locale}.md
try {
const fileContent = fs.readFileSync(
path.join('./src/pages', `${route === '/' ? 'index' : route}.md`),
path.join('./src/pages', `${route === '/' ? 'index' : route}/index.md`),
'utf8'
);
const data = fm(fileContent);

2
src/components/status-check.tsx

@ -11,7 +11,7 @@ import { STATUS_CHECKER_URL } from '@common/constants';
import { css } from '@stacks/ui-core';
import { getCapsizeStyles } from '@components/mdx/typography';
const fetcher = url => fetch(url).then(r => r.json());
const fetcher = url => fetch(url.replace(navigator.language, '')).then(r => r.json());
type Status = 'online' | 'slow' | 'degraded' | 'loading' | undefined;

0
src/pages/404.md → src/pages/404/index.md

18
src/pages/_middleware.tsx

@ -0,0 +1,18 @@
import { NextRequest, NextResponse } from 'next/server';
import { SUPPORTED_LANGUAGES } from '../common/constants';
export function middleware(request: NextRequest) {
if (request.nextUrl.pathname.includes('/api/')) {
return undefined;
}
const shouldHandleLocale =
!request.nextUrl.pathname.includes('/favicon') &&
!request.nextUrl.pathname.includes('/static/');
const locale = request.headers.get('accept-language').substr(0, 2);
if ((shouldHandleLocale && !SUPPORTED_LANGUAGES.includes(locale)) || locale === 'en') {
return undefined;
} else if (!request.nextUrl.pathname.includes(locale)) {
return NextResponse.redirect(`/${locale}${request.nextUrl.pathname}`);
}
}

0
src/pages/api/status.js → src/pages/api/status/index.js

0
src/pages/build-apps/overview.md → src/pages/build-apps/overview/index.md

0
src/pages/build-apps/references/authentication.md → src/pages/build-apps/references/authentication/index.md

0
src/pages/build-apps/references/bns.md → src/pages/build-apps/references/bns/index.md

0
src/pages/build-apps/references/gaia.md → src/pages/build-apps/references/gaia/index.md

0
src/pages/contributing.md → src/pages/contributing/index.md

21
src/pages/index/index.md

@ -0,0 +1,21 @@
---
title: Stacks documentation
description: Learn about Stacks mining, the STX token, and the Clarity smart contract language
---
-> Content related to developer tools and app development has recently moved to [docs.hiro.so](https://docs.hiro.so/). For more information on the content move, see [this post](https://forum.stacks.org/t/the-evolution-of-the-stacks-documentation-and-a-new-hiro-docs-site/12343) on the Stacks forum.
## Understand Stacks
[@page-reference | grid]
| /understand-stacks/overview, /understand-stacks/proof-of-transfer, /understand-stacks/testnet
## Write smart contracts
[@page-reference | grid]
| /write-smart-contracts/overview, /write-smart-contracts/tokens
## Start mining
[@page-reference | grid]
| /start-mining/mainnet, /start-mining/testnet

0
src/pages/references/bns-contract.md → src/pages/references/bns-contract/index.md

0
src/pages/references/deploy-tips.md → src/pages/references/deploy-tips/index.md

0
src/pages/references/faqs.md → src/pages/references/faqs/index.md

0
src/pages/references/glossary.md → src/pages/references/glossary/index.md

0
src/pages/references/language-functions.md → src/pages/references/language-functions/index.md

0
src/pages/references/language-keywords.md → src/pages/references/language-keywords/index.md

0
src/pages/references/language-overview.md → src/pages/references/language-overview/index.md

0
src/pages/references/language-types.md → src/pages/references/language-types/index.md

0
src/pages/references/stacking-contract.md → src/pages/references/stacking-contract/index.md

0
src/pages/references/stacks-node-configuration.md → src/pages/references/stacks-node-configuration/index.md

0
src/pages/start-mining/mainnet.md → src/pages/start-mining/mainnet/index.md

0
src/pages/start-mining/testnet.md → src/pages/start-mining/testnet/index.md

0
src/pages/understand-stacks/accounts.md → src/pages/understand-stacks/accounts/index.md

0
src/pages/understand-stacks/microblocks.md → src/pages/understand-stacks/microblocks/index.md

0
src/pages/understand-stacks/mining.md → src/pages/understand-stacks/mining/index.md

0
src/pages/understand-stacks/network.md → src/pages/understand-stacks/network/index.md

0
src/pages/understand-stacks/overview.md → src/pages/understand-stacks/overview/index.md

0
src/pages/understand-stacks/proof-of-transfer.md → src/pages/understand-stacks/proof-of-transfer/index.md

0
src/pages/understand-stacks/running-mainnet-node.md → src/pages/understand-stacks/running-mainnet-node/index.md

0
src/pages/understand-stacks/running-testnet-node.md → src/pages/understand-stacks/running-testnet-node/index.md

0
src/pages/understand-stacks/stacking.md → src/pages/understand-stacks/stacking/index.md

0
src/pages/understand-stacks/stacks-blockchain-api.md → src/pages/understand-stacks/stacks-blockchain-api/index.md

0
src/pages/understand-stacks/technical-specs.md → src/pages/understand-stacks/technical-specs/index.md

0
src/pages/understand-stacks/testnet.md → src/pages/understand-stacks/testnet/index.md

0
src/pages/understand-stacks/transactions.md → src/pages/understand-stacks/transactions/index.md

0
src/pages/write-smart-contracts/overview.md → src/pages/write-smart-contracts/overview/index.md

0
src/pages/write-smart-contracts/principals.md → src/pages/write-smart-contracts/principals/index.md

0
src/pages/write-smart-contracts/tokens.md → src/pages/write-smart-contracts/tokens/index.md

0
src/pages/write-smart-contracts/values.md → src/pages/write-smart-contracts/values/index.md

3065
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save