Skip to content

Commit

Permalink
Merge branch 'master' into fix-textarea-disabled-color
Browse files Browse the repository at this point in the history
  • Loading branch information
korkt-kim committed Apr 17, 2024
2 parents d7dab01 + 273104c commit d5affa1
Show file tree
Hide file tree
Showing 18 changed files with 2,518 additions and 2,286 deletions.
73 changes: 63 additions & 10 deletions .dumi/theme/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createHash } from 'crypto';
import fs from 'fs';
import path from 'path';
import { createHash } from 'crypto';
import createEmotionServer from '@emotion/server/create-instance';
import chalk from 'chalk';
import type { IApi, IRoute } from 'dumi';
import ReactTechStack from 'dumi/dist/techStacks/react';
import chalk from 'chalk';
import sylvanas from 'sylvanas';
import createEmotionServer from '@emotion/server/create-instance';

import localPackage from '../../package.json';

function extractEmotionStyle(html: string) {
Expand Down Expand Up @@ -53,13 +54,65 @@ class AntdReactTechStack extends ReactTechStack {

if (md) {
// extract description & css style from md file
const description = md.match(
new RegExp(`(?:^|\\n)## ${locale}([^]+?)(\\n## [a-z]|\\n\`\`\`|\\n<style>|$)`),
)?.[1];
const style = md.match(/\r?\n(?:```css|<style>)\r?\n([^]+?)\r?\n(?:```|<\/style>)/)?.[1];

props.description ??= description?.trim();
props.style ??= style;
const blocks: Record<string, string> = {};

const lines = md.split('\n');

let blockName = '';
let cacheList: string[] = [];

// Get block name
const getBlockName = (text: string) => {
if (text.startsWith('## ')) {
return text.replace('## ', '').trim();
}

if (text.startsWith('```css') || text.startsWith('<style>')) {
return 'style';
}

return null;
};

// Fill block content
const fillBlock = (name: string, lineList: string[]) => {
if (lineList.length) {
let fullText: string;

if (name === 'style') {
fullText = lineList
.join('\n')
.replace(/<\/?style>/g, '')
.replace(/```(\s*css)/g, '');
} else {
fullText = lineList.slice(1).join('\n');
}

blocks[name] = fullText;
}
};

for (let i = 0; i < lines.length; i++) {
const line = lines[i];

// Mark as new block
const nextBlockName = getBlockName(line);
if (nextBlockName) {
fillBlock(blockName, cacheList);

// Next Block
blockName = nextBlockName;
cacheList = [line];
} else {
cacheList.push(line);
}
}

// Last block
fillBlock(blockName, cacheList);

props.description = blocks[locale];
props.style = blocks.style;
}
}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
types: [opened, synchronize]

permissions:
issues: write
contents: read

jobs:
Expand Down

0 comments on commit d5affa1

Please sign in to comment.