Skip to content

Commit c1801d2

Browse files
committed
build & deplay
1 parent a09aee6 commit c1801d2

7 files changed

Lines changed: 334 additions & 1 deletion

File tree

‎GenerateShit/browser/index.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { generate } from '../lib/generator.js';
2+
import { createRandomPicker } from '../lib/random.js';
3+
4+
const defaultCorpus = require('../corpus/data.json');
5+
6+
async function loadCorpus(corpuspath) {
7+
if (corpuspath) {
8+
const corpus = await (await fetch(corpuspath)).json();
9+
return corpus;
10+
}
11+
return defaultCorpus;
12+
}
13+
14+
export { generate, createRandomPicker, loadCorpus };

‎GenerateShit/build.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { build } from 'esbuild';
2+
3+
const buildOptions = {
4+
entryPoints: ['./browser/index.js'],
5+
outfile: './dist/index.js',
6+
bundle: true,
7+
minify: true,
8+
};
9+
10+
build(buildOptions);

‎GenerateShit/dist/index.js‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎GenerateShit/index.html‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>狗屁不通文章生成器</title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
11+
<body>
12+
<header>
13+
<div class="options">
14+
<div>最小字数:<input id="min" type="range" min="500" max="5000" step="100" value="2000"><span>2000</span></div>
15+
<div>最大字数:<input id="max" type="range" min="1000" max="10000" step="100" value="5000"><span>5000</span>
16+
</div>
17+
</div>
18+
<div class="ref"><a href="https://github.com/menzi11/BullshitGenerator">原版</a></div>
19+
<div class="title"><span>标题:</span><input id="title" type="text" value="">
20+
<button id="generate">生成</button>
21+
<button id="anotherTitle">换一个</button>
22+
</div>
23+
</header>
24+
<main>
25+
<article></article>
26+
</main>
27+
<script type="module">
28+
import { generate } from './lib/generator.js';
29+
import { createRandomPicker } from './lib/random.js';
30+
31+
const options = document.querySelector('.options');
32+
const config = { min: 2000, max: 5000 };
33+
options.addEventListener('change', ({ target }) => {
34+
const num = Number(target.value);
35+
config[target.id] = num;
36+
target.parentNode.querySelector('input + span').innerHTML = num;
37+
});
38+
const generateButton = document.getElementById('generate');
39+
const anotherTitleButton = document.getElementById('anotherTitle');
40+
const article = document.querySelector('article');
41+
const titleEl = document.getElementById('title');
42+
43+
(async function () {
44+
const corpus = await (await fetch('./corpus/data.json')).json();
45+
const pickTitle = createRandomPicker(corpus.title);
46+
titleEl.value = pickTitle();
47+
generateButton.addEventListener('click', () => {
48+
const text = generate(titleEl.value, { corpus, ...config });
49+
article.innerHTML = `<section>${text.join('</section><section>')}</section>`;
50+
});
51+
anotherTitleButton.addEventListener('click', () => {
52+
titleEl.value = pickTitle();
53+
if (article.innerHTML) generateButton.click();
54+
});
55+
}());
56+
</script>
57+
</body>
58+
59+
</html>

‎GenerateShit/package-lock.json‎

Lines changed: 184 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎GenerateShit/package.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
"type": "module",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
9-
"start": "node index.js"
9+
"start": "node index.js",
10+
"build": "node build.js"
1011
},
1112
"author": "ranxiu",
1213
"license": "MIT",
1314
"dependencies": {
1415
"command-line-args": "^5.2.1",
1516
"command-line-usage": "^6.1.3",
1617
"moment": "^2.29.4"
18+
},
19+
"devDependencies": {
20+
"esbuild": "^0.15.13"
1721
}
1822
}

‎GenerateShit/style.css‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
header {
2+
height: 120px;
3+
border-bottom: solid 1px #777;
4+
}
5+
.options {
6+
float: right;
7+
display: flex;
8+
flex-direction: column;
9+
}
10+
.options div {
11+
width: 300px;
12+
}
13+
#title {
14+
font-size: 1.5rem;
15+
}
16+
.title {
17+
clear: both;
18+
line-height: 60px;
19+
text-align: center;
20+
font-size: 1.5rem;
21+
padding-top: 12px;
22+
}
23+
.title input {
24+
outline: none;
25+
border: none;
26+
border-bottom: solid 1px black;
27+
text-align: center;
28+
width: 45%;
29+
max-width: 600px;
30+
}
31+
.options input {
32+
margin-right: 10px;
33+
}
34+
.title button {
35+
font-size: 1.5rem;
36+
margin-left: 10px;
37+
border: none;
38+
background: #444;
39+
color: #eee;
40+
}
41+
main {
42+
padding-bottom: 40px;
43+
}
44+
section {
45+
text-indent: 3rem;
46+
padding: 10px 0;
47+
}
48+
footer {
49+
position: fixed;
50+
width: 100%;
51+
bottom: 0;
52+
background-color: white;
53+
}
54+
@media screen and (max-width: 480px) {
55+
.title span {display: none;}
56+
#title {font-size: 1.2rem;}
57+
.title button {
58+
font-size: 1.2rem;
59+
}
60+
section {text-indent: 2.4rem;}
61+
}

0 commit comments

Comments
 (0)