-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-staticbase.sh
More file actions
executable file
·1485 lines (1223 loc) · 39.4 KB
/
Copy pathcreate-staticbase.sh
File metadata and controls
executable file
·1485 lines (1223 loc) · 39.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# staticbase - Simple Website Generator
# Creates a basic website with index, about, contact, and blog pages
# Powered by Vite, Tailwind CSS, and Alpine.js
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get project name from argument or use default
PROJECT_NAME="${1:-mystaticbase}"
PROJECT_PATH="./$PROJECT_NAME"
echo -e "${BLUE}🚀 Creating staticbase project: ${PROJECT_NAME}${NC}"
# Check if directory exists
if [ -d "$PROJECT_PATH" ]; then
echo -e "${RED}❌ Error: Directory already exists: ${PROJECT_NAME}${NC}"
exit 1
fi
# Create project structure
echo -e "${GREEN}📁 Creating directories...${NC}"
mkdir -p "$PROJECT_PATH"/{src,public/images,content/blog,templates,lib}
# Create package.json
cat > "$PROJECT_PATH/package.json" << 'EOF'
{
"name": "PROJECT_NAME_PLACEHOLDER",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"alpinejs": "^3.15.3",
"vite": "^7.3.1"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.18",
"@tailwindcss/typography": "^0.5.13",
"gray-matter": "^4.0.3",
"marked": "^17.0.1",
"tailwindcss": "^4.1.18",
"vite-plugin-virtual-mpa": "^1.12.1"
}
}
EOF
sed -i.bak "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/" "$PROJECT_PATH/package.json" && rm "$PROJECT_PATH/package.json.bak"
# Create .gitignore
cat > "$PROJECT_PATH/.gitignore" << 'EOF'
node_modules/
dist/
.DS_Store
.env
.env.local
*.log
EOF
# Create vite.config.js
cat > "$PROJECT_PATH/vite.config.js" << 'EOFVITE'
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
import { createMpaPlugin } from "vite-plugin-virtual-mpa";
import { resolve } from "path";
import { readFileSync } from "fs";
import { getContentFromDirectory, formatDate } from "./lib/content.js";
import { generateBlogCard } from "./lib/templates.js";
const __dirname = resolve();
const blogDir = resolve(__dirname, "content/blog");
const blogPosts = getContentFromDirectory(blogDir, {
sortBy: "date",
order: "desc",
});
const recentBlogPosts = blogPosts.slice(0, 3);
const blogListTemplate = readFileSync(
resolve(__dirname, "templates/blog-list.html"),
"utf-8"
);
const blogPostTemplate = readFileSync(
resolve(__dirname, "templates/blog-post.html"),
"utf-8"
);
const indexContent = readFileSync(resolve(__dirname, "index.html"), "utf-8");
const aboutContent = readFileSync(resolve(__dirname, "about.html"), "utf-8");
const contactContent = readFileSync(resolve(__dirname, "contact.html"), "utf-8");
function generateBlogListContent() {
const cardsHtml = blogPosts
.map((post) => generateBlogCard(post))
.join("\n");
return blogListTemplate.replace("<%- blogCards %>", cardsHtml);
}
function generateBlogPostContent(post) {
const { frontmatter, content } = post;
const dateFormatted = formatDate(frontmatter.date);
return blogPostTemplate
.replace(/<%=\s*title\s*%>/g, frontmatter.title)
.replace(/<%=\s*date\s*%>/g, dateFormatted)
.replace(/<%-\s*content\s*%>/g, content);
}
function generateHomepageContent() {
const recentBlogHtml = recentBlogPosts
.map((post) => generateBlogCard(post))
.join("\n");
return indexContent.replace("<%- recentBlogPosts %>", recentBlogHtml);
}
const pages = [
{
name: "index",
entry: "/src/main.js",
data: {
title: "Home - PROJECT_NAME_PLACEHOLDER",
description: "Welcome to my website",
activePage: "home",
content: generateHomepageContent(),
},
},
{
name: "about",
entry: "/src/main.js",
data: {
title: "About - PROJECT_NAME_PLACEHOLDER",
description: "Learn more about us",
activePage: "about",
content: aboutContent,
},
},
{
name: "contact",
entry: "/src/main.js",
data: {
title: "Contact - PROJECT_NAME_PLACEHOLDER",
description: "Get in touch",
activePage: "contact",
content: contactContent,
},
},
{
name: "blog",
entry: "/src/main.js",
data: {
title: "Blog - PROJECT_NAME_PLACEHOLDER",
description: "Read our latest posts",
activePage: "blog",
content: generateBlogListContent(),
},
},
...blogPosts.map((post) => ({
name: `blog-${post.slug}`,
filename: `blog/${post.slug}.html`,
entry: "/src/main.js",
data: {
title: `${post.frontmatter.title} - PROJECT_NAME_PLACEHOLDER`,
description: post.frontmatter.description,
activePage: "blog",
content: generateBlogPostContent(post),
},
})),
];
const rewrites = [
...blogPosts.map((post) => ({
from: new RegExp(`^/blog/${post.slug}(\\.html)?$`),
to: `/blog/${post.slug}.html`,
})),
];
export default defineConfig({
plugins: [
tailwindcss(),
createMpaPlugin({
template: "base.html",
pages,
rewrites,
}),
],
});
EOFVITE
sed -i.bak "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/g" "$PROJECT_PATH/vite.config.js" && rm "$PROJECT_PATH/vite.config.js.bak"
# Create base.html
cat > "$PROJECT_PATH/base.html" << 'EOFBASE'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= title %></title>
<meta name="description" content="<%= description %>" />
<script type="module" src="/src/main.js"></script>
</head>
<body class="min-h-screen bg-gray-50 text-gray-900 antialiased" x-data="{ mobileMenuOpen: false }">
<!-- Navigation -->
<nav class="bg-white border-b border-gray-200 sticky top-0 z-50 shadow-sm">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-16">
<!-- Logo -->
<a href="/" class="text-2xl font-bold text-blue-600 hover:text-blue-700 transition-colors">
PROJECT_NAME_PLACEHOLDER
</a>
<!-- Desktop Navigation -->
<ul class="hidden md:flex space-x-8">
<li>
<a
href="/"
class="<%= activePage === 'home' ? 'text-blue-600 font-semibold' : 'text-gray-700 hover:text-blue-600' %> transition-colors"
>
Home
</a>
</li>
<li>
<a
href="/about.html"
class="<%= activePage === 'about' ? 'text-blue-600 font-semibold' : 'text-gray-700 hover:text-blue-600' %> transition-colors"
>
About
</a>
</li>
<li>
<a
href="/blog.html"
class="<%= activePage === 'blog' ? 'text-blue-600 font-semibold' : 'text-gray-700 hover:text-blue-600' %> transition-colors"
>
Blog
</a>
</li>
<li>
<a
href="/contact.html"
class="<%= activePage === 'contact' ? 'text-blue-600 font-semibold' : 'text-gray-700 hover:text-blue-600' %> transition-colors"
>
Contact
</a>
</li>
</ul>
<!-- Mobile Menu Button -->
<button
@click="mobileMenuOpen = !mobileMenuOpen"
class="md:hidden p-2 rounded-lg hover:bg-gray-100 transition-colors"
>
<svg x-show="!mobileMenuOpen" class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
</svg>
<svg x-show="mobileMenuOpen" class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<!-- Mobile Menu -->
<div
x-show="mobileMenuOpen"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 -translate-y-1"
x-transition:enter-end="opacity-100 translate-y-0"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100 translate-y-0"
x-transition:leave-end="opacity-0 -translate-y-1"
class="md:hidden pb-4"
>
<ul class="space-y-2">
<li>
<a href="/" class="block px-4 py-2 rounded-lg <%= activePage === 'home' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-700 hover:bg-gray-50' %>">
Home
</a>
</li>
<li>
<a href="/about.html" class="block px-4 py-2 rounded-lg <%= activePage === 'about' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-700 hover:bg-gray-50' %>">
About
</a>
</li>
<li>
<a href="/blog.html" class="block px-4 py-2 rounded-lg <%= activePage === 'blog' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-700 hover:bg-gray-50' %>">
Blog
</a>
</li>
<li>
<a href="/contact.html" class="block px-4 py-2 rounded-lg <%= activePage === 'contact' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-700 hover:bg-gray-50' %>">
Contact
</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="min-h-[calc(100vh-16rem)]">
<%- content %>
</main>
<!-- Footer -->
<footer class="bg-white border-t border-gray-200 mt-16">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<p class="text-center text-gray-600">
© 2026 PROJECT_NAME_PLACEHOLDER. All rights reserved.
</p>
</div>
</footer>
</body>
</html>
EOFBASE
sed -i.bak "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/g" "$PROJECT_PATH/base.html" && rm "$PROJECT_PATH/base.html.bak"
# Create index.html
cat > "$PROJECT_PATH/index.html" << 'EOFINDEX'
<!-- Hero Section -->
<section class="bg-gradient-to-br from-blue-600 to-blue-800 text-white py-20">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
<h1 class="text-4xl md:text-6xl font-bold mb-6">
Welcome to PROJECT_NAME_PLACEHOLDER
</h1>
<p class="text-xl md:text-2xl text-blue-100 mb-8">
A simple, clean website built with staticbase
</p>
<a
href="/blog.html"
class="inline-block bg-white text-blue-600 px-8 py-3 rounded-lg font-semibold hover:bg-blue-50 transition-colors shadow-lg hover:shadow-xl"
>
Read Our Blog
</a>
</div>
</section>
<!-- Recent Blog Posts -->
<section class="py-16">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
<h2 class="text-3xl font-bold text-gray-900 mb-8">Recent Blog Posts</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<%- recentBlogPosts %>
</div>
<div class="text-center mt-12">
<a
href="/blog.html"
class="inline-block bg-blue-600 text-white px-6 py-3 rounded-lg font-semibold hover:bg-blue-700 transition-colors"
>
View All Posts
</a>
</div>
</div>
</section>
EOFINDEX
sed -i.bak "s/PROJECT_NAME_PLACEHOLDER/$PROJECT_NAME/g" "$PROJECT_PATH/index.html" && rm "$PROJECT_PATH/index.html.bak"
# Create about.html
cat > "$PROJECT_PATH/about.html" << 'EOF'
<section class="py-16">
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8">
<h1 class="text-4xl font-bold text-gray-900 mb-6">About Us</h1>
<div class="prose prose-lg max-w-none">
<p class="text-xl text-gray-600 mb-6">
Welcome to our website! We're passionate about creating great content and sharing our knowledge with the world.
</p>
<h2 class="text-2xl font-bold text-gray-900 mt-8 mb-4">Our Mission</h2>
<p class="text-gray-600 mb-6">
Our mission is to provide valuable content and resources to our readers. We believe in simplicity, clarity, and user-friendly design.
</p>
<h2 class="text-2xl font-bold text-gray-900 mt-8 mb-4">What We Do</h2>
<p class="text-gray-600 mb-6">
We write about various topics including technology, design, and development. Our blog features tutorials, insights, and tips to help you grow.
</p>
<div class="bg-blue-50 border border-blue-200 rounded-lg p-6 mt-8">
<h3 class="text-xl font-semibold text-blue-900 mb-2">Get in Touch</h3>
<p class="text-blue-700">
Interested in working together? <a href="/contact.html" class="underline hover:text-blue-900">Contact us</a> to learn more.
</p>
</div>
</div>
</div>
</section>
EOF
# Create contact.html
cat > "$PROJECT_PATH/contact.html" << 'EOF'
<section class="py-16">
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8">
<h1 class="text-4xl font-bold text-gray-900 mb-6">Contact Us</h1>
<p class="text-xl text-gray-600 mb-8">
We'd love to hear from you! Get in touch using the form below.
</p>
<div id="successMessage" class="hidden bg-green-50 border border-green-200 text-green-800 px-4 py-3 rounded-lg mb-4">
Thank you for your message! We'll get back to you soon.
</div>
<div id="errorMessage" class="hidden bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-lg mb-4">
Something went wrong. Please try again.
</div>
<form id="contactForm" class="space-y-6">
<div>
<label for="name" class="block text-sm font-medium text-gray-700 mb-2">
Name
</label>
<input
type="text"
id="name"
name="name"
required
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors"
/>
<span id="nameError" class="hidden text-sm text-red-600 mt-1">Please enter your name</span>
</div>
<div>
<label for="email" class="block text-sm font-medium text-gray-700 mb-2">
Email
</label>
<input
type="email"
id="email"
name="email"
required
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors"
/>
<span id="emailError" class="hidden text-sm text-red-600 mt-1">Please enter a valid email address</span>
</div>
<div>
<label for="message" class="block text-sm font-medium text-gray-700 mb-2">
Message
</label>
<textarea
id="message"
name="message"
rows="5"
required
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors"
></textarea>
<span id="messageError" class="hidden text-sm text-red-600 mt-1">Please enter a message</span>
</div>
<button
type="submit"
id="submitBtn"
class="w-full bg-blue-600 text-white px-6 py-3 rounded-lg font-semibold hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
<span id="submitText">Send Message</span>
</button>
</form>
</div>
</section>
EOF
# Create templates/blog-list.html
cat > "$PROJECT_PATH/templates/blog-list.html" << 'EOF'
<section class="py-16">
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
<h1 class="text-4xl font-bold text-gray-900 mb-4">Blog</h1>
<p class="text-xl text-gray-600 mb-12">Thoughts, tutorials, and insights</p>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<%- blogCards %>
</div>
</div>
</section>
EOF
# Create templates/blog-post.html
cat > "$PROJECT_PATH/templates/blog-post.html" << 'EOF'
<article class="py-16">
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8">
<header class="mb-8 pb-8 border-b border-gray-200">
<h1 class="text-4xl font-bold text-gray-900 mb-4"><%= title %></h1>
<time datetime="<%= date %>" class="text-gray-600">
<%= date %>
</time>
</header>
<div class="prose prose-lg max-w-none prose-headings:font-bold prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline prose-img:rounded-lg prose-pre:bg-gray-900 prose-pre:text-gray-100">
<%- content %>
</div>
<div class="mt-12 pt-8 border-t border-gray-200">
<a
href="/blog.html"
class="inline-flex items-center text-blue-600 hover:text-blue-700 font-semibold"
>
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
Back to Blog
</a>
</div>
</div>
</article>
EOF
# Create lib/content.js
cat > "$PROJECT_PATH/lib/content.js" << 'EOF'
import { readFileSync, readdirSync, existsSync } from "fs";
import { join, basename } from "path";
import matter from "gray-matter";
import { marked } from "marked";
marked.setOptions({
gfm: true,
breaks: true,
});
export function parseMarkdownFile(filePath) {
const fileContent = readFileSync(filePath, "utf-8");
const { data: frontmatter, content } = matter(fileContent);
const html = marked(content);
return {
frontmatter,
content: html,
slug: frontmatter.slug || basename(filePath, ".md"),
};
}
export function getContentFromDirectory(contentDir, options = {}) {
const { sortBy = "date", order = "desc", filterDraft = true } = options;
if (!existsSync(contentDir)) {
return [];
}
const files = readdirSync(contentDir).filter((f) => f.endsWith(".md"));
const items = files.map((file) => {
const filePath = join(contentDir, file);
return parseMarkdownFile(filePath);
});
const filtered = filterDraft
? items.filter((item) => !item.frontmatter.draft)
: items;
return filtered.sort((a, b) => {
const aVal = a.frontmatter[sortBy];
const bVal = b.frontmatter[sortBy];
if (sortBy === "date") {
return order === "desc"
? new Date(bVal) - new Date(aVal)
: new Date(aVal) - new Date(bVal);
}
return order === "desc" ? bVal - aVal : aVal - bVal;
});
}
export function formatDate(date) {
return new Date(date).toLocaleDateString("en-US", {
month: "long",
day: "numeric",
year: "numeric",
});
}
EOF
# Create lib/templates.js
cat > "$PROJECT_PATH/lib/templates.js" << 'EOF'
export function generateBlogCard(post) {
const { frontmatter } = post;
const date = new Date(frontmatter.date).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
});
return `
<article class="bg-white border border-gray-200 rounded-lg p-6 hover:shadow-lg transition-shadow">
<h3 class="text-xl font-bold text-gray-900 mb-2">
<a href="/blog/${post.slug}.html" class="hover:text-blue-600 transition-colors">
${frontmatter.title}
</a>
</h3>
<time datetime="${frontmatter.date}" class="text-sm text-gray-500 block mb-3">
${date}
</time>
<p class="text-gray-600 mb-4">${frontmatter.description || ''}</p>
<a
href="/blog/${post.slug}.html"
class="inline-flex items-center text-blue-600 hover:text-blue-700 font-semibold"
>
Read More
<svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
</svg>
</a>
</article>
`;
}
EOF
# Create src/main.js
cat > "$PROJECT_PATH/src/main.js" << 'EOF'
import './style.css';
import Alpine from 'alpinejs';
// Make Alpine available globally
window.Alpine = Alpine;
// Start Alpine
Alpine.start();
// Contact Form Handler
document.addEventListener('DOMContentLoaded', () => {
const contactForm = document.getElementById('contactForm');
if (!contactForm) return;
const submitBtn = document.getElementById('submitBtn');
const submitText = document.getElementById('submitText');
const successMessage = document.getElementById('successMessage');
const errorMessage = document.getElementById('errorMessage');
const nameInput = document.getElementById('name');
const emailInput = document.getElementById('email');
const messageInput = document.getElementById('message');
const nameError = document.getElementById('nameError');
const emailError = document.getElementById('emailError');
const messageError = document.getElementById('messageError');
// Validation functions
const validateEmail = (email) => {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
};
const validateName = (name) => {
return name.trim().length > 0;
};
const validateMessage = (message) => {
return message.trim().length > 0;
};
const showError = (input, errorElement, message) => {
input.classList.add('border-red-500');
errorElement.textContent = message;
errorElement.classList.remove('hidden');
};
const hideError = (input, errorElement) => {
input.classList.remove('border-red-500');
errorElement.classList.add('hidden');
};
// Real-time validation
nameInput.addEventListener('blur', () => {
if (!validateName(nameInput.value)) {
showError(nameInput, nameError, 'Please enter your name');
} else {
hideError(nameInput, nameError);
}
});
emailInput.addEventListener('blur', () => {
if (!validateEmail(emailInput.value)) {
showError(emailInput, emailError, 'Please enter a valid email address');
} else {
hideError(emailInput, emailError);
}
});
messageInput.addEventListener('blur', () => {
if (!validateMessage(messageInput.value)) {
showError(messageInput, messageError, 'Please enter a message');
} else {
hideError(messageInput, messageError);
}
});
// Form submission
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
// Hide previous messages
successMessage.classList.add('hidden');
errorMessage.classList.add('hidden');
// Validate all fields
let isValid = true;
if (!validateName(nameInput.value)) {
showError(nameInput, nameError, 'Please enter your name');
isValid = false;
} else {
hideError(nameInput, nameError);
}
if (!validateEmail(emailInput.value)) {
showError(emailInput, emailError, 'Please enter a valid email address');
isValid = false;
} else {
hideError(emailInput, emailError);
}
if (!validateMessage(messageInput.value)) {
showError(messageInput, messageError, 'Please enter a message');
isValid = false;
} else {
hideError(messageInput, messageError);
}
if (!isValid) {
return;
}
// Disable submit button
submitBtn.disabled = true;
submitText.textContent = 'Sending...';
try {
// Prepare form data
const formData = {
name: nameInput.value.trim(),
email: emailInput.value.trim(),
message: messageInput.value.trim()
};
// Submit to API, change xxx to your form ID
const response = await fetch('https://a.firaform.com/api/f/xxx', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(formData)
});
if (response.ok) {
// Show success message
successMessage.classList.remove('hidden');
// Reset form
contactForm.reset();
// Scroll to success message
successMessage.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
} else {
// Show error message
errorMessage.classList.remove('hidden');
}
} catch (error) {
console.error('Form submission error:', error);
errorMessage.classList.remove('hidden');
} finally {
// Re-enable submit button
submitBtn.disabled = false;
submitText.textContent = 'Send Message';
}
});
});
console.log('staticbase loaded with Tailwind CSS and Alpine.js!');
EOF
# Create src/style.css
cat > "$PROJECT_PATH/src/style.css" << 'EOF'
@import "tailwindcss";
@plugin "@tailwindcss/typography";
EOF
# Create sample blog posts
cat > "$PROJECT_PATH/content/blog/welcome.md" << 'EOF'
---
title: "Welcome to staticbase"
slug: welcome
date: 2026-01-28
description: "Your first blog post using staticbase with Tailwind CSS and Alpine.js"
---
# Welcome to staticbase!
This is your first blog post. staticbase makes it easy to create a simple, clean website with a blog, powered by modern tools:
- **Tailwind CSS** for beautiful, utility-first styling
- **Alpine.js** for lightweight interactivity
- **Vite** for lightning-fast builds
- **Markdown** for easy content writing
## Getting Started
Edit this file or create new markdown files in the `content/blog` directory to add more posts.
Each post needs frontmatter with:
- **title**: The post title
- **slug**: URL-friendly identifier
- **date**: Publication date (YYYY-MM-DD)
- **description**: Short description for SEO
## Writing Content
You can use all standard Markdown features:
- Bulleted lists
- **Bold** and *italic* text
- [Links](https://example.com)
- Code blocks
- Images
- And more!
### Code Example
```javascript
function greet(name) {
console.log(`Hello, ${name}!`);
}
greet('World');
```
## Next Steps
1. Customize your site colors in Tailwind config
2. Add more pages or blog posts
3. Deploy to your favorite hosting platform
Happy blogging! 🚀
EOF
cat > "$PROJECT_PATH/content/blog/getting-started.md" << 'EOF'
---
title: "Getting Started with Your New Site"
slug: getting-started
date: 2026-01-27
description: "Learn how to customize your new staticbase website with Tailwind CSS and Alpine.js"
---
# Getting Started
Congratulations on setting up your new website! Here's how to customize it and make it your own.
## Project Structure
```
mystaticbase/
├── content/
│ └── blog/ # Blog posts (markdown)
├── templates/ # Page templates
├── lib/ # Helper functions
├── src/
│ ├── main.js # JavaScript + Alpine.js
│ └── style.css # Tailwind CSS
├── public/
│ └── images/ # Static images
├── index.html # Homepage content
├── about.html # About page content
├── contact.html # Contact page content
├── base.html # Base template with navigation
└── vite.config.js # Vite configuration
```
## Adding Blog Posts
Create a new `.md` file in `content/blog/` with frontmatter:
```markdown
---
title: "My Post Title"
slug: my-post-title
date: 2026-01-28
description: "Post description"
---
Your content here...
```
## Customizing Styles
staticbase uses Tailwind CSS. You can customize the theme by editing `src/style.css`:
```css
@import "tailwindcss";
@theme {
/* Add custom colors */
--color-brand: #3b82f6;
}
```
Or use Tailwind's utility classes directly in your HTML:
```html
<div class="bg-blue-600 text-white p-8 rounded-lg">
Custom styled component
</div>
```
## Adding Interactivity with Alpine.js
Alpine.js is already set up! Add interactive components easily:
```html
<div x-data="{ open: false }">
<button @click="open = !open">Toggle</button>
<div x-show="open">Content</div>
</div>
```
## Deployment
Build your site for production:
```bash
npm run build
```
The `dist/` folder can be deployed to:
- **Netlify** - Drag & drop deployment
- **Vercel** - Git integration
- **GitHub Pages** - Free hosting
- **Cloudflare Pages** - Fast global CDN
## Learn More
- [Tailwind CSS Docs](https://tailwindcss.com/docs)
- [Alpine.js Docs](https://alpinejs.dev/)
- [Vite Guide](https://vitejs.dev/guide/)
- [Markdown Guide](https://www.markdownguide.org/)
Enjoy building your site! ✨
EOF
# Create README
cat > "$PROJECT_PATH/README.md" << 'EOFREADME'
# PROJECT_NAME_PLACEHOLDER
A modern, clean website built with staticbase.
## Features
- 📄 Static pages (Home, About, Contact)
- 📝 Markdown-based blog
- ⚡ Fast development with Vite
- 🎨 Tailwind CSS for styling
- 🏔️ Alpine.js for interactivity
- 📱 Fully responsive design
## Getting Started
```bash
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
```
## Tech Stack
- **Vite** - Lightning fast build tool
- **Tailwind CSS** - Utility-first CSS framework
- **Alpine.js** - Lightweight JavaScript framework
- **Marked** - Markdown parser
- **Gray Matter** - Frontmatter parser
## Project Structure
```
PROJECT_NAME_PLACEHOLDER/
├── content/blog/ # Blog posts (markdown files)
├── templates/ # Page templates
├── src/
│ ├── main.js # JavaScript + Alpine.js setup
│ └── style.css # Tailwind CSS
├── lib/ # Helper functions
├── public/images/ # Static assets
├── index.html # Homepage content
├── about.html # About page content
├── contact.html # Contact page content
├── base.html # Base template with navigation
└── vite.config.js # Vite configuration
```
## Adding Blog Posts
Create a new `.md` file in `content/blog/`: