Skip to content

Commit

Permalink
style: Modify the code formatting maximum number of words per line!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed May 20, 2024
1 parent 61cdc4d commit 01696fa
Show file tree
Hide file tree
Showing 64 changed files with 437 additions and 1,009 deletions.
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ node_modules
.analyze.html

build

*.mdx

LICENSE

CNAME
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"printWidth": 100,
"singleQuote": true,
"arrowParens": "always",
"semi": true,
Expand Down
6 changes: 6 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ index.html
.analyze.html

build

*.mdx

LICENSE

CNAME
13 changes: 1 addition & 12 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,7 @@ module.exports = {
'type-enum': [
2,
'always',
[
'feat',
'fix',
'docs',
'style',
'refactor',
'perf',
'test',
'chore',
'revert',
'build'
]
['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'revert', 'build']
],
'type-case': [0],
'type-empty': [0],
Expand Down
6 changes: 1 addition & 5 deletions helpers/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ function getHref(path: string) {

function writeSubmited(submitedList: string[]) {
try {
writeFileSync(
submitedPath,
`export default ${JSON.stringify(submitedList, null, 2)}`,
'utf-8'
);
writeFileSync(submitedPath, `export default ${JSON.stringify(submitedList, null, 2)}`, 'utf-8');
} catch (err) {
console.log('write fail', err);
}
Expand Down
31 changes: 7 additions & 24 deletions helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export const routesPath = resolve('src/routes.tsx');

export const parseRoute = (path: string) => path.split(sep).pop()!.slice(0, -4);

export const replaceFileExtension = (name: string) =>
name.slice(0, name.lastIndexOf('.')) + '.tsx';
export const replaceFileExtension = (name: string) => name.slice(0, name.lastIndexOf('.')) + '.tsx';

export const generateRouteJSONWithArticle = async () => {
const paths = await fast.glob(['./src/markdowns/**/*.mdx']);
Expand All @@ -56,13 +55,9 @@ export const generateRouteJSONWithArticle = async () => {
.map((path) => resolve(path))
.forEach((path) => {
const route = parseRoute(path);
const { attributes } = frontmatter<ArticleMeta>(
readFileSync(path, 'utf-8')
);
const { attributes } = frontmatter<ArticleMeta>(readFileSync(path, 'utf-8'));

const aliasPath = path
.replace('./src/markdowns', '@/markdowns')
.replace(/\\/g, '/');
const aliasPath = path.replace('./src/markdowns', '@/markdowns').replace(/\\/g, '/');

const str = `
{
Expand All @@ -85,9 +80,7 @@ export const generateRouteJSONWithArticle = async () => {
export const getExampleMeta = (path: string) => {
const text = readFileSync(path, 'utf-8');

const match = text
.match(/(?<=\/\/--meta:)([\s\S]*)(?=\/\/--endmeta)/)?.[0]
.trim();
const match = text.match(/(?<=\/\/--meta:)([\s\S]*)(?=\/\/--endmeta)/)?.[0].trim();

const arr = match!.replace(/\/\/\s/g, '').split(/[\n\r]/);

Expand All @@ -104,12 +97,7 @@ const template = readFileSync(resolve('./src/coder/Wrapper.tsx'), 'utf-8');
export const generateRouteJSONWithExample = async () => {
let result = '';

async function transform(
dirs: string[],
parent: string,
hierarchy: number,
root: string
) {
async function transform(dirs: string[], parent: string, hierarchy: number, root: string) {
if (hierarchy === 0) {
const directory = resolve(parent, `code`);
const value = template.replace('base64_coder/Index', `${root}/Index`);
Expand Down Expand Up @@ -156,9 +144,7 @@ export const generateRouteJSONWithExample = async () => {

const newName = replaceFileExtension(name);

const paths = relative(resolve(examples, root), parent)
.split(sep)
.filter(Boolean);
const paths = relative(resolve(examples, root), parent).split(sep).filter(Boolean);
const folder = resolve(examples, root, 'code', ...paths);

if (!existsSync(folder)) {
Expand Down Expand Up @@ -207,10 +193,7 @@ export const generateRouteJSON = async () => {
};
};

export const replacePlaceRoute = (
code: string,
{ books, articles, examples }: RoutePlace
) =>
export const replacePlaceRoute = (code: string, { books, articles, examples }: RoutePlace) =>
code
.replace('/** placeholder for articles */', articles)
.replace('/** placeholder for books */', books)
Expand Down
4 changes: 1 addition & 3 deletions helpers/vite-generate-sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ function viteGenerateSitemap(): PluginOption {
}

const routeJSON = await generateRouteJSON();
const getRoutes = new Function(
`return ${replacePlaceRoute(`[${match[0]}]`, routeJSON)}`
);
const getRoutes = new Function(`return ${replacePlaceRoute(`[${match[0]}]`, routeJSON)}`);

const detailsRoutes = resolveFullRoutes(getRoutes(), '', []);

Expand Down
25 changes: 6 additions & 19 deletions helpers/vite-generateSw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ declare class Queue {
private _syncInProgress;
private _requestsAddedDuringSync;

constructor(
name: string,
{ forceSyncFallback, onSync, maxRetentionTime }?: QueueOptions
);
constructor(name: string, { forceSyncFallback, onSync, maxRetentionTime }?: QueueOptions);

get name(): string;

Expand Down Expand Up @@ -131,9 +128,7 @@ export interface CacheDidUpdateCallbackParam {

export interface BroadcastCacheUpdateOptions {
headersToCheck?: string[];
generatePayload?: (
options: CacheDidUpdateCallbackParam
) => Record<string, any>;
generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>;
notifyAllClients?: boolean;
}

Expand Down Expand Up @@ -178,9 +173,7 @@ export interface CachedResponseWillBeUsedCallbackParam {
state?: PluginState;
}
export interface CachedResponseWillBeUsedCallback {
(
param: CachedResponseWillBeUsedCallbackParam
): Promise<Response | void | null | undefined>;
(param: CachedResponseWillBeUsedCallbackParam): Promise<Response | void | null | undefined>;
}

export interface CacheKeyWillBeUsedCallbackParam {
Expand All @@ -201,9 +194,7 @@ export interface CacheWillUpdateCallbackParam {
state?: PluginState;
}
export interface CacheWillUpdateCallback {
(
param: CacheWillUpdateCallbackParam
): Promise<Response | void | null | undefined>;
(param: CacheWillUpdateCallbackParam): Promise<Response | void | null | undefined>;
}
export interface CachedResponseWillBeUsedCallbackParam {
cacheName: string;
Expand All @@ -214,9 +205,7 @@ export interface CachedResponseWillBeUsedCallbackParam {
state?: PluginState;
}
export interface CachedResponseWillBeUsedCallback {
(
param: CachedResponseWillBeUsedCallbackParam
): Promise<Response | void | null | undefined>;
(param: CachedResponseWillBeUsedCallbackParam): Promise<Response | void | null | undefined>;
}
export interface FetchDidFailCallbackParam {
error: Error;
Expand Down Expand Up @@ -521,9 +510,7 @@ const defaultConfig = {
name: 'vite:workbox'
};

export default function vitePluginWorkbox({
mode
}: ConfigParams): PluginOption {
export default function vitePluginWorkbox({ mode }: ConfigParams): PluginOption {
if (mode === 'development') {
return defaultConfig;
}
Expand Down
29 changes: 6 additions & 23 deletions helpers/vite-prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ const reg = /(?<=export const routes: RouteObject\[\] = \[)([\s\S]*)(?=\];)/;

const match = text.match(reg);

const excludeOutPathRewrite = [
'/',
'/articles',
'/examples',
'/books',
'/coder',
'/profile'
];
const excludeOutPathRewrite = ['/', '/articles', '/examples', '/books', '/coder', '/profile'];

function getMetaTag(meta: ArticleMeta | undefined, route: ResolveRouteObject) {
const env = getEnv();
Expand Down Expand Up @@ -135,9 +128,7 @@ async function vitePrerender(mode: string) {
}

const routeJSON = await generateRouteJSON();
const getRoutes = new Function(
`return ${replacePlaceRoute(`[${match[0]}]`, routeJSON)}`
);
const getRoutes = new Function(`return ${replacePlaceRoute(`[${match[0]}]`, routeJSON)}`);

const detailsRoutes = resolveFullRoutes(getRoutes(), '', []);
const routes = detailsRoutes.map((route) => route.fullPath);
Expand Down Expand Up @@ -174,18 +165,10 @@ async function vitePrerender(mode: string) {
renderedRoute.outputPath = 'build' + renderedRoute.originalRoute;
}

renderedRoute.html = renderedRoute.html.replace(
'<html lang="en"',
'<html lang="zh-CN"'
);
renderedRoute.html = renderedRoute.html.replace(
/alignItems/g,
'align-items'
);

const route = detailsRoutes.find(
(route) => route.fullPath === renderedRoute.originalRoute
);
renderedRoute.html = renderedRoute.html.replace('<html lang="en"', '<html lang="zh-CN"');
renderedRoute.html = renderedRoute.html.replace(/alignItems/g, 'align-items');

const route = detailsRoutes.find((route) => route.fullPath === renderedRoute.originalRoute);
if (route) {
renderedRoute.html = renderedRoute.html.replace(
'<!-- meta_place -->',
Expand Down
7 changes: 1 addition & 6 deletions helpers/vite-route-generator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
generateRouteJSON,
replacePlaceRoute,
resolve,
routesPath
} from './utils';
import { generateRouteJSON, replacePlaceRoute, resolve, routesPath } from './utils';

import type { PluginOption } from 'vite';
import { createFilter } from 'vite';
Expand Down
36 changes: 7 additions & 29 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { createContext, useEffect, useRef } from 'react';

import {
Button,
ConfigProvider,
message,
Modal,
notification,
theme
} from 'antd';
import { Button, ConfigProvider, message, Modal, notification, theme } from 'antd';
import type { MessageInstance } from 'antd/es/message/interface';
import type { HookAPI } from 'antd/es/modal/useModal';
import type { NotificationInstance } from 'antd/es/notification/interface';
Expand Down Expand Up @@ -82,9 +75,7 @@ const App: React.FC<IAppProps> = (props) => {

if (hasLocalStorage('app')) {
setLanguage(getStorage<AppState>('app')?.settings?.language || 'zh-CN');
setColorScheme(
getStorage<AppState>('app')?.settings?.colorScheme || 'light'
);
setColorScheme(getStorage<AppState>('app')?.settings?.colorScheme || 'light');
} else {
setLanguage(language);
if (darkModeQuery.matches) {
Expand Down Expand Up @@ -134,10 +125,7 @@ const App: React.FC<IAppProps> = (props) => {
const listenerVisibilityChange = () => {
setFrontDesk(!window.document.hidden);
};
window.document.addEventListener(
'visibilitychange',
listenerVisibilityChange
);
window.document.addEventListener('visibilitychange', listenerVisibilityChange);

const cancelGlobalUserTipsEventListener = globalEvent.on(
'user_tips',
Expand All @@ -152,19 +140,14 @@ const App: React.FC<IAppProps> = (props) => {
}
);

const cancelListenerReLoad = assetsLoadHandle.reLoadByOnline(
() => !enableServiceWorkerCache
);
const cancelListenerReLoad = assetsLoadHandle.reLoadByOnline(() => !enableServiceWorkerCache);

return () => {
cancelListenerReLoad();
cancelGlobalUserTipsEventListener();
cancelGlobalUserAlertEventListener();
darkModeQuery.removeEventListener('change', listenerColorSchemeChange);
window.document.removeEventListener(
'visibilitychange',
listenerVisibilityChange
);
window.document.removeEventListener('visibilitychange', listenerVisibilityChange);
};
}, []);

Expand All @@ -179,15 +162,10 @@ const App: React.FC<IAppProps> = (props) => {
token: {
colorPrimary: '#ff6000'
},
algorithm:
colorScheme === 'dark'
? theme.darkAlgorithm
: theme.defaultAlgorithm
algorithm: colorScheme === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm
}}
>
<AppContext.Provider value={appProvider.current}>
{props.children}
</AppContext.Provider>
<AppContext.Provider value={appProvider.current}>{props.children}</AppContext.Provider>
</ConfigProvider>
</>
);
Expand Down
7 changes: 2 additions & 5 deletions src/assets/styles/prism-one-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ pre[class*='language-'] {
background: hsl(220, 13%, 18%);
color: hsl(220, 14%, 71%);
text-shadow: 0 1px rgba(0, 0, 0, 0.3);
font-family: 'Fira Code', 'Fira Mono', Menlo, Consolas, 'DejaVu Sans Mono',
monospace;
font-family: 'Fira Code', 'Fira Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
direction: ltr;
text-align: left;
white-space: pre;
Expand Down Expand Up @@ -311,9 +310,7 @@ div.code-toolbar > .toolbar.toolbar > .toolbar-item > span:focus {

/* Hovering over a linkable line number (in the gutter area) */
/* Requires Line Numbers plugin as well */
pre[id].linkable-line-numbers.linkable-line-numbers
span.line-numbers-rows
> span:hover:before {
pre[id].linkable-line-numbers.linkable-line-numbers span.line-numbers-rows > span:hover:before {
background-color: hsla(220, 100%, 80%, 0.04);
}

Expand Down
Loading

0 comments on commit 01696fa

Please sign in to comment.