Skip to content

Commit d1fe582

Browse files
committed
fix: 🐛 初始化内容
1 parent 4d2e184 commit d1fe582

9 files changed

Lines changed: 330 additions & 40 deletions

File tree

src-tauri/src/main.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4-
5-
mod folder;
64
mod file;
7-
8-
use tauri::WindowEvent;
9-
5+
mod folder;
106

117
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
128
#[tauri::command]
139
fn greet(name: &str) -> String {
1410
format!("Hello, {}! You've been greeted from Rust!", name)
1511
}
1612

17-
1813
fn main() {
1914
tauri::Builder::default()
2015
.plugin(tauri_plugin_clipboard_manager::init())
@@ -25,30 +20,12 @@ fn main() {
2520
.plugin(tauri_plugin_fs::init())
2621
.plugin(tauri_plugin_shell::init())
2722
.plugin(tauri_plugin_window_state::Builder::default().build())
28-
29-
.on_window_event(|window, event| {
30-
match event {
31-
32-
// WindowEvent::Focused(true) => {
33-
// window.emit("window-focused", {}).unwrap();
34-
// }
35-
WindowEvent::CloseRequested { api, .. } => {
36-
#[cfg(target_os = "macos")]
37-
{
38-
window.minimize().unwrap();
39-
}
40-
41-
#[cfg(not(target_os = "macos"))]
42-
{
43-
window.close().unwrap();
44-
}
45-
46-
api.prevent_close();
47-
}
48-
_ => {}
49-
}
50-
})
51-
.invoke_handler(tauri::generate_handler![file::read_dir, folder::show_in_folder, file::search_keyword_in_dir, greet])
23+
.invoke_handler(tauri::generate_handler![
24+
file::read_dir,
25+
folder::show_in_folder,
26+
file::search_keyword_in_dir,
27+
greet
28+
])
5229
.run(tauri::generate_context!())
5330
.expect("error while running tauri application");
5431
}

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242
},
4343
"productName": "MDX Editor",
44-
"version": "0.9.5",
44+
"version": "0.9.6",
4545
"identifier": "editor.runjs.cool",
4646
"plugins": {
4747
"updater": {

src/components/Pen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default function Pen({
156156
async function compileNow(content) {
157157
console.log('compile', filePath)
158158
let md = resultRef.current?.md || ''
159-
if (isMdFile(filePath)) {
159+
if (isMdFile(filePath) || !filePath) {
160160
md = content
161161
}
162162
console.log('md', md)

src/pages/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import React, { useState, useEffect } from 'react'
22

33
import {
44
exists,
5-
create,
65
writeTextFile,
7-
readTextFile,
6+
mkdir,
87
BaseDirectory,
98
} from '@tauri-apps/plugin-fs'
10-
import initial from '@/utils/initial/'
9+
import initial from '@/utils/initial'
1110
import { documentDir, resolve } from '@tauri-apps/api/path'
1211
import useLocalStorage from 'react-use/lib/useLocalStorage'
1312
import { isMdFile } from '@/components/utils/file-tree-util'
@@ -27,13 +26,20 @@ export default function Page() {
2726
const path = await resolve(documentDirPath, 'mdx-editor')
2827

2928
if (!(await exists(path))) {
30-
await create('mdx-editor', {
29+
await mkdir('mdx-editor', {
30+
baseDir: BaseDirectory.Document,
31+
})
32+
await mkdir('mdx-editor/plugins', {
33+
baseDir: BaseDirectory.Document,
34+
})
35+
await mkdir('mdx-editor/plugins/themes', {
3136
baseDir: BaseDirectory.Document,
3237
})
3338

3439
for (const key in initial) {
3540
const content = initial[key]
36-
await writeTextFile(path + `/${key}.md`, content)
41+
42+
await writeTextFile(`${path}/${key}`, content)
3743
}
3844
}
3945
setDirPath(path)

src/utils/initial/custom.css

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
body {
2+
--weui-BG-0: #ededed;
3+
--weui-BG-2: #fff;
4+
--weui-FG-0: rgba(0, 0, 0, 0.9);
5+
--weui-FG-HALF: rgba(0, 0, 0, 0.9);
6+
--weui-FG-1: rgba(0, 0, 0, 0.55);
7+
--weui-FG-3: rgba(0, 0, 0, 0.1);
8+
--weui-BRAND: #07c160;
9+
--weui-LINK: #576b95;
10+
}
11+
12+
body.dark {
13+
--weui-BG-0: #111;
14+
--weui-BG-2: #191919;
15+
--weui-FG-0: rgba(255, 255, 255, 0.8);
16+
--weui-FG-HALF: rgba(255, 255, 255, 0.6);
17+
--weui-FG-1: rgba(255, 255, 255, 0.5);
18+
--weui-FG-3: rgba(255, 255, 255, 0.1);
19+
--weui-BRAND: #07c160;
20+
--weui-LINK: #7d90a9;
21+
}
22+
23+
body {
24+
color: var(--weui-FG-HALF);
25+
background-color: var(--weui-BG-2);
26+
}
27+
/*默认样式,最佳实践*/
28+
29+
/*全局属性*/
30+
.markdown-body {
31+
word-spacing: 0px;
32+
letter-spacing: 0px;
33+
word-break: break-word;
34+
word-wrap: break-word;
35+
text-align: left;
36+
}
37+
38+
/*段落*/
39+
.markdown-body p {
40+
margin-top: 16px;
41+
margin-bottom: 16px;
42+
}
43+
44+
/*标题*/
45+
.markdown-body h1,
46+
.markdown-body h2,
47+
.markdown-body h3,
48+
.markdown-body h4,
49+
.markdown-body h5,
50+
.markdown-body h6 {
51+
margin-top: 30px;
52+
margin-bottom: 15px;
53+
padding: 0px;
54+
font-weight: bold;
55+
color: var(--weui-FG-0);
56+
}
57+
.markdown-body h1 {
58+
font-size: 24px;
59+
}
60+
.markdown-body h2 {
61+
font-size: 22px;
62+
}
63+
.markdown-body h3 {
64+
font-size: 20px;
65+
}
66+
.markdown-body h4 {
67+
font-size: 18px;
68+
}
69+
.markdown-body h5 {
70+
font-size: 16px;
71+
}
72+
.markdown-body h6 {
73+
font-size: 14px;
74+
}
75+
76+
/*列表*/
77+
.markdown-body ul,
78+
.markdown-body ol {
79+
margin-top: 8px;
80+
margin-bottom: 8px;
81+
padding-left: 25px;
82+
}
83+
.markdown-body ul {
84+
list-style-type: disc;
85+
}
86+
.markdown-body ul ul {
87+
list-style-type: square;
88+
}
89+
90+
.markdown-body ol {
91+
list-style-type: decimal;
92+
}
93+
94+
.markdown-body li section {
95+
margin-top: 5px;
96+
margin-bottom: 5px;
97+
line-height: 26px;
98+
text-align: left;
99+
font-weight: 500;
100+
}
101+
102+
/*引用*/
103+
.markdown-body blockquote {
104+
background-color: var(--weui-BG-0);
105+
border-left: 4px solid var(--weui-BRAND);
106+
color: var(--weui-FG-HALF);
107+
padding: 1px 16px;
108+
margin: 16px 0;
109+
border-radius: 5px;
110+
}
111+
112+
.markdown-body blockquote p {
113+
line-height: 26px;
114+
color: var(--weui-FG-HALF);
115+
}
116+
117+
/*链接*/
118+
.markdown-body a,
119+
.markdown-body .link {
120+
text-decoration: none;
121+
color: var(--weui-BRAND);
122+
word-wrap: break-word;
123+
}
124+
125+
/*加粗*/
126+
.markdown-body strong {
127+
font-weight: bold;
128+
}
129+
130+
/*斜体*/
131+
.markdown-body em {
132+
font-style: italic;
133+
}
134+
135+
/*加粗斜体*/
136+
.markdown-body em strong {
137+
font-weight: bold;
138+
}
139+
140+
/*删除线*/
141+
.markdown-body del {
142+
font-style: italic;
143+
}
144+
145+
/*分隔线*/
146+
.markdown-body hr {
147+
height: 1px;
148+
margin: 0;
149+
margin-top: 10px;
150+
margin-bottom: 10px;
151+
border: none;
152+
border-top: 1px solid var(--weui-FG-3);
153+
}
154+
155+
/*行内代码*/
156+
.markdown-body p code,
157+
.markdown-body li code {
158+
font-size: 14px;
159+
word-break: break-word;
160+
padding: 2px 4px;
161+
border-radius: 4px;
162+
margin: 0 2px;
163+
color: var(--weui-BRAND);
164+
background-color: var(--weui-BG-0);
165+
font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;
166+
}
167+
168+
.markdown-body pre {
169+
font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;
170+
overflow: auto;
171+
position: relative;
172+
line-height: 1.75;
173+
}
174+
175+
.markdown-body pre > code {
176+
min-width: 100%;
177+
font-size: 12px;
178+
word-break: normal;
179+
display: block;
180+
flex: none;
181+
padding: 12px;
182+
-webkit-overflow-scrolling: touch;
183+
}
184+
185+
/*图片*/
186+
.markdown-body img {
187+
display: block;
188+
max-width: 100%;
189+
}
190+
.qrcode-block img {
191+
border-radius: 0;
192+
box-shadow: none;
193+
}
194+
195+
/*图片*/
196+
.markdown-body figure {
197+
margin: 0;
198+
padding: 0 5px;
199+
margin-top: 10px;
200+
margin-bottom: 10px;
201+
}
202+
203+
/*图片描述文字*/
204+
.markdown-body figcaption {
205+
margin-top: 5px;
206+
text-align: center;
207+
color: var(--weui-LINK);
208+
font-size: 14px;
209+
}
210+
211+
/*表格*/
212+
.markdown-body table {
213+
width: auto;
214+
table-layout: auto;
215+
text-align: left;
216+
margin-top: 2em;
217+
margin-bottom: 2em;
218+
font-size: 0.875rem;
219+
line-height: 1.25rem;
220+
border-spacing: 0;
221+
border: 1px solid var(--weui-FG-3);
222+
border-collapse: collapse;
223+
}
224+
225+
.markdown-body table tr {
226+
border: 0;
227+
}
228+
229+
.markdown-body table tr th,
230+
.markdown-body table tr td {
231+
border: 0;
232+
border-bottom: 1px solid var(--weui-FG-3);
233+
font-size: 16px;
234+
padding: 10px;
235+
text-align: left;
236+
}
237+
238+
.markdown-body table tr th {
239+
color: var(--weui-FG-0);
240+
background-color: var(--weui-BG-0);
241+
font-weight: bold;
242+
}
243+
244+
.markdown-body sub,
245+
sup {
246+
line-height: 0;
247+
}
248+
249+
.markdown-body .contains-task-list {
250+
padding-left: 0;
251+
}
252+
.markdown-body .task-list-item {
253+
list-style: none;
254+
}
255+
256+
.snowfall {
257+
display: flex;
258+
align-items: flex-end;
259+
justify-content: center;
260+
}
261+
262+
.snowfall-bar {
263+
flex-basis: 0;
264+
flex-grow: 1;
265+
margin: 4px;
266+
display: flex;
267+
justify-content: center;
268+
align-items: end;
269+
font-size: 10px;
270+
color: #eff6ff;
271+
}

0 commit comments

Comments
 (0)