init
This commit is contained in:
commit
d69342b2e9
160 changed files with 28681 additions and 0 deletions
15
internal/build/assets/assets.go
Normal file
15
internal/build/assets/assets.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed css js
|
||||
var staticFS embed.FS
|
||||
|
||||
func Handler() http.Handler {
|
||||
sub, _ := fs.Sub(staticFS, ".")
|
||||
return http.FileServer(http.FS(sub))
|
||||
}
|
||||
778
internal/build/assets/css/style.css
Normal file
778
internal/build/assets/css/style.css
Normal file
|
|
@ -0,0 +1,778 @@
|
|||
/* WriteKit - Blog Stylesheet */
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--accent: #2563eb;
|
||||
--font-body: system-ui, -apple-system, sans-serif;
|
||||
--font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
|
||||
|
||||
--text: #18181b;
|
||||
--text-muted: #71717a;
|
||||
--bg: #ffffff;
|
||||
--bg-secondary: #fafafa;
|
||||
--border: #e4e4e7;
|
||||
|
||||
--content-width: 680px;
|
||||
--spacing: 1.5rem;
|
||||
|
||||
/* Compactness defaults (cozy) */
|
||||
--content-spacing: 1.75rem;
|
||||
--paragraph-spacing: 1.25rem;
|
||||
--heading-spacing: 2.5rem;
|
||||
--line-height: 1.7;
|
||||
}
|
||||
|
||||
/* Compactness: Compact */
|
||||
.compactness-compact {
|
||||
--content-spacing: 1.25rem;
|
||||
--paragraph-spacing: 0.875rem;
|
||||
--heading-spacing: 1.75rem;
|
||||
--line-height: 1.55;
|
||||
}
|
||||
|
||||
/* Compactness: Cozy (default) */
|
||||
.compactness-cozy {
|
||||
--content-spacing: 1.75rem;
|
||||
--paragraph-spacing: 1.25rem;
|
||||
--heading-spacing: 2.5rem;
|
||||
--line-height: 1.7;
|
||||
}
|
||||
|
||||
/* Compactness: Spacious */
|
||||
.compactness-spacious {
|
||||
--content-spacing: 2.25rem;
|
||||
--paragraph-spacing: 1.5rem;
|
||||
--heading-spacing: 3rem;
|
||||
--line-height: 1.85;
|
||||
}
|
||||
|
||||
/* Layout: Minimal */
|
||||
.layout-minimal .site-header {
|
||||
justify-content: center;
|
||||
}
|
||||
.layout-minimal .site-nav {
|
||||
display: none;
|
||||
}
|
||||
.layout-minimal .site-footer {
|
||||
border-top: none;
|
||||
opacity: 0.7;
|
||||
}
|
||||
.layout-minimal .profile {
|
||||
margin-bottom: 3.5rem;
|
||||
}
|
||||
|
||||
/* Layout: Magazine */
|
||||
.layout-magazine .posts-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 1.25rem;
|
||||
}
|
||||
.layout-magazine .post-card {
|
||||
padding: 1.5rem;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg);
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
.layout-magazine .post-card:hover {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
.layout-magazine .post-card-title {
|
||||
font-size: 1.0625rem;
|
||||
}
|
||||
.layout-magazine .post-card-description {
|
||||
font-size: 0.875rem;
|
||||
-webkit-line-clamp: 2;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 16px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: var(--font-body);
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.site-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
max-width: var(--content-width);
|
||||
margin: 0 auto;
|
||||
padding: 2rem var(--spacing);
|
||||
}
|
||||
|
||||
.site-name {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
color: var(--text);
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.site-name:hover {
|
||||
text-decoration: none;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.site-nav {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.site-nav a {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 450;
|
||||
}
|
||||
|
||||
.site-nav a:hover {
|
||||
color: var(--text);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Main */
|
||||
main {
|
||||
max-width: var(--content-width);
|
||||
margin: 0 auto;
|
||||
padding: 0 var(--spacing) 3rem;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
.site-footer {
|
||||
max-width: var(--content-width);
|
||||
margin: 0 auto;
|
||||
padding: 2.5rem var(--spacing);
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8125rem;
|
||||
border-top: 1px solid var(--border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.powered-by {
|
||||
color: var(--text-muted);
|
||||
text-decoration: none;
|
||||
font-size: 0.75rem;
|
||||
opacity: 0.7;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.powered-by:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Profile */
|
||||
.profile {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border-radius: 50%;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.profile-name {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.25rem;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.profile-bio {
|
||||
color: var(--text-muted);
|
||||
max-width: 380px;
|
||||
margin: 0 auto;
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* Post List */
|
||||
.posts-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--content-spacing);
|
||||
}
|
||||
|
||||
.post-card a {
|
||||
display: block;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.post-card a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.post-card-date {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.post-card-title {
|
||||
margin: 0.375rem 0 0;
|
||||
font-size: 1.1875rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.015em;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.post-card a:hover .post-card-title {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.post-card-description {
|
||||
margin: 0.5rem 0 0;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.no-posts {
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
padding: 3rem 0;
|
||||
}
|
||||
|
||||
/* Pagination */
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 3rem;
|
||||
padding-top: 1.5rem;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
/* Post Header */
|
||||
.post-header {
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
.post-date {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
margin: 0.5rem 0 0;
|
||||
font-size: 2.25rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
|
||||
.post-description {
|
||||
font-size: 1.125rem;
|
||||
color: var(--text-muted);
|
||||
margin: 0.75rem 0 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.post-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-muted);
|
||||
background: var(--bg-secondary);
|
||||
padding: 0.25rem 0.625rem;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.post-cover {
|
||||
margin: 1.75rem 0 0;
|
||||
}
|
||||
|
||||
.post-cover img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-radius: 0.5rem;
|
||||
aspect-ratio: 16 / 9;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
/* Prose */
|
||||
.prose {
|
||||
line-height: var(--line-height);
|
||||
font-size: 1.0625rem;
|
||||
}
|
||||
|
||||
.prose > *:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.prose h2 {
|
||||
margin-top: var(--heading-spacing);
|
||||
margin-bottom: var(--paragraph-spacing);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.prose h3 {
|
||||
margin-top: calc(var(--heading-spacing) * 0.8);
|
||||
margin-bottom: calc(var(--paragraph-spacing) * 0.8);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.015em;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.prose h4 {
|
||||
margin-top: calc(var(--heading-spacing) * 0.65);
|
||||
margin-bottom: calc(var(--paragraph-spacing) * 0.65);
|
||||
font-size: 1.0625rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.prose p {
|
||||
margin: var(--paragraph-spacing) 0;
|
||||
}
|
||||
|
||||
.prose ul, .prose ol {
|
||||
margin: var(--paragraph-spacing) 0;
|
||||
padding-left: 1.375rem;
|
||||
}
|
||||
|
||||
.prose li {
|
||||
margin: calc(var(--paragraph-spacing) * 0.4) 0;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
|
||||
.prose li::marker {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.prose blockquote {
|
||||
margin: var(--content-spacing) 0;
|
||||
padding: 0 0 0 1.25rem;
|
||||
border-left: 2px solid var(--border);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.prose blockquote p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.prose pre {
|
||||
margin: var(--content-spacing) 0;
|
||||
padding: 1.125rem 1.25rem;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
overflow-x: auto;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.prose code {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.875em;
|
||||
background: var(--bg-secondary);
|
||||
padding: 0.175rem 0.375rem;
|
||||
border-radius: 0.25rem;
|
||||
font-variant-ligatures: none;
|
||||
}
|
||||
|
||||
.prose pre code {
|
||||
background: none;
|
||||
padding: 0;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
.prose img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 0.375rem;
|
||||
margin: var(--content-spacing) 0;
|
||||
}
|
||||
|
||||
.prose a {
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
|
||||
}
|
||||
|
||||
.prose a:hover {
|
||||
text-decoration-color: var(--accent);
|
||||
}
|
||||
|
||||
.prose hr {
|
||||
margin: var(--heading-spacing) 0;
|
||||
border: none;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.prose strong {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.prose table {
|
||||
width: 100%;
|
||||
margin: var(--content-spacing) 0;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
.prose th, .prose td {
|
||||
padding: 0.625rem 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.prose th {
|
||||
background: var(--bg-secondary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Reactions & Comments */
|
||||
.reactions, .comments {
|
||||
margin-top: 3.5rem;
|
||||
padding-top: 2rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.comments-title {
|
||||
margin: 0 0 1.25rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.reaction-buttons {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.reaction-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.5rem 0.875rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 2rem;
|
||||
background: var(--bg);
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.reaction-btn:hover {
|
||||
background: var(--bg-secondary);
|
||||
border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
|
||||
}
|
||||
|
||||
.reaction-btn.active {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.reaction-btn .count {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Search */
|
||||
.search-trigger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.375rem 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
background: var(--bg);
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
|
||||
.search-trigger:hover {
|
||||
border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
|
||||
}
|
||||
|
||||
.search-trigger kbd {
|
||||
padding: 0.125rem 0.375rem;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 0.25rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.6875rem;
|
||||
}
|
||||
|
||||
.search-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.search-modal.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.search-modal-backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
backdrop-filter: blur(2px);
|
||||
}
|
||||
|
||||
.search-modal-content {
|
||||
position: absolute;
|
||||
top: 15%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 90%;
|
||||
max-width: 520px;
|
||||
background: var(--bg);
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.2);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#search-input {
|
||||
width: 100%;
|
||||
padding: 1rem 1.25rem;
|
||||
border: none;
|
||||
font-size: 1rem;
|
||||
outline: none;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
#search-input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.search-results {
|
||||
max-height: 320px;
|
||||
overflow-y: auto;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.search-result {
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.search-result:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.search-result a {
|
||||
display: block;
|
||||
padding: 0.875rem 1.25rem;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.search-result a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.search-result:hover, .search-result.focused {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.search-result-title {
|
||||
font-weight: 500;
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
.search-result-snippet {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-muted);
|
||||
margin-top: 0.25rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.search-result mark {
|
||||
background: color-mix(in srgb, var(--accent) 25%, transparent);
|
||||
color: inherit;
|
||||
border-radius: 0.125rem;
|
||||
padding: 0 0.125rem;
|
||||
}
|
||||
|
||||
.search-hint {
|
||||
padding: 0.625rem 1.25rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.search-hint kbd {
|
||||
padding: 0.125rem 0.375rem;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 0.25rem;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.search-no-results {
|
||||
padding: 1.5rem 1.25rem;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
/* Comment Form */
|
||||
.comment-form textarea {
|
||||
width: 100%;
|
||||
padding: 0.875rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
font-family: inherit;
|
||||
font-size: 0.9375rem;
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
|
||||
.comment-form textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.comment-form button {
|
||||
margin-top: 0.75rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
|
||||
.comment-form button:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Comments List */
|
||||
.comments-list {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.comment {
|
||||
padding: 1.25rem 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.comment:first-child {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.comment:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.comment-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
margin-bottom: 0.625rem;
|
||||
}
|
||||
|
||||
.comment-avatar {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.comment-author {
|
||||
font-weight: 500;
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
.comment-date {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* Auth Prompt */
|
||||
.auth-prompt {
|
||||
padding: 1.25rem;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 0.375rem;
|
||||
text-align: center;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.auth-prompt a {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Mobile */
|
||||
@media (max-width: 640px) {
|
||||
:root {
|
||||
--spacing: 1.25rem;
|
||||
}
|
||||
|
||||
.site-header {
|
||||
padding: 1.5rem var(--spacing);
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 1.75rem;
|
||||
}
|
||||
|
||||
.prose {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.prose h2 {
|
||||
font-size: 1.375rem;
|
||||
}
|
||||
|
||||
.prose h3 {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
}
|
||||
127
internal/build/assets/js/main.js
Normal file
127
internal/build/assets/js/main.js
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
// Live reload when studio saves settings
|
||||
const channel = new BroadcastChannel('writekit-studio');
|
||||
channel.onmessage = function(event) {
|
||||
if (event.data.type === 'settings-changed') {
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initSearch);
|
||||
|
||||
function initSearch() {
|
||||
const trigger = document.getElementById('search-trigger');
|
||||
const modal = document.getElementById('search-modal');
|
||||
const backdrop = modal?.querySelector('.search-modal-backdrop');
|
||||
const input = document.getElementById('search-input');
|
||||
const results = document.getElementById('search-results');
|
||||
|
||||
if (!trigger || !modal || !input || !results) return;
|
||||
|
||||
let debounceTimer;
|
||||
|
||||
function open() {
|
||||
modal.classList.add('active');
|
||||
document.body.style.overflow = 'hidden';
|
||||
input.value = '';
|
||||
results.innerHTML = '';
|
||||
setTimeout(() => input.focus(), 10);
|
||||
}
|
||||
|
||||
function close() {
|
||||
modal.classList.remove('active');
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
trigger.addEventListener('click', open);
|
||||
backdrop.addEventListener('click', close);
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === '/' && !modal.classList.contains('active') &&
|
||||
!['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) {
|
||||
e.preventDefault();
|
||||
open();
|
||||
}
|
||||
if (e.key === 'Escape' && modal.classList.contains('active')) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
input.addEventListener('input', function() {
|
||||
const query = this.value.trim();
|
||||
clearTimeout(debounceTimer);
|
||||
|
||||
if (query.length < 2) {
|
||||
results.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
debounceTimer = setTimeout(() => search(query), 150);
|
||||
});
|
||||
|
||||
input.addEventListener('keydown', function(e) {
|
||||
const items = results.querySelectorAll('.search-result');
|
||||
const focused = results.querySelector('.search-result.focused');
|
||||
|
||||
if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
if (!focused && items.length) {
|
||||
items[0].classList.add('focused');
|
||||
} else if (focused?.nextElementSibling) {
|
||||
focused.classList.remove('focused');
|
||||
focused.nextElementSibling.classList.add('focused');
|
||||
}
|
||||
} else if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
if (focused?.previousElementSibling) {
|
||||
focused.classList.remove('focused');
|
||||
focused.previousElementSibling.classList.add('focused');
|
||||
}
|
||||
} else if (e.key === 'Enter' && focused) {
|
||||
e.preventDefault();
|
||||
const link = focused.querySelector('a');
|
||||
if (link) window.location.href = link.href;
|
||||
}
|
||||
});
|
||||
|
||||
async function search(query) {
|
||||
try {
|
||||
const res = await fetch('/api/reader/search?q=' + encodeURIComponent(query));
|
||||
const data = await res.json();
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
results.innerHTML = '<div class="search-no-results">No results found</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
results.innerHTML = data.map(r => `
|
||||
<div class="search-result">
|
||||
<a href="${r.url}">
|
||||
<div class="search-result-title">${highlight(r.title, query)}</div>
|
||||
${r.description ? `<div class="search-result-snippet">${highlight(r.description, query)}</div>` : ''}
|
||||
</a>
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (e) {
|
||||
results.innerHTML = '<div class="search-no-results">Search failed</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function highlight(text, query) {
|
||||
if (!text) return '';
|
||||
const escaped = escapeHtml(text);
|
||||
const tokens = query.split(/\s+/).filter(t => t.length > 0);
|
||||
if (!tokens.length) return escaped;
|
||||
const pattern = tokens.map(t => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
||||
return escaped.replace(new RegExp(`(${pattern})`, 'gi'), '<mark>$1</mark>');
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
}
|
||||
})();
|
||||
197
internal/build/assets/js/post.js
Normal file
197
internal/build/assets/js/post.js
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
var WriteKit = (function() {
|
||||
'use strict';
|
||||
|
||||
let config = {};
|
||||
let user = null;
|
||||
|
||||
async function init(opts) {
|
||||
config = opts;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/reader/me');
|
||||
const data = await res.json();
|
||||
if (data.logged_in) {
|
||||
user = data.user;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (config.reactions) initReactions();
|
||||
if (config.comments) initComments();
|
||||
}
|
||||
|
||||
async function initReactions() {
|
||||
const container = document.querySelector('.reactions-container');
|
||||
if (!container) return;
|
||||
|
||||
const res = await fetch(`/api/reader/posts/${config.slug}/reactions`);
|
||||
const data = await res.json();
|
||||
|
||||
const counts = data.counts || {};
|
||||
const userReactions = data.user || [];
|
||||
|
||||
if (config.reactionMode === 'upvote') {
|
||||
const emoji = config.reactionEmojis[0] || '👍';
|
||||
const count = counts[emoji] || 0;
|
||||
const active = userReactions.includes(emoji);
|
||||
|
||||
container.innerHTML = `
|
||||
<button class="reaction-btn ${active ? 'active' : ''}" data-emoji="${emoji}">
|
||||
<span class="emoji">${emoji}</span>
|
||||
<span class="count">${count}</span>
|
||||
</button>
|
||||
`;
|
||||
} else {
|
||||
container.innerHTML = config.reactionEmojis.map(emoji => {
|
||||
const count = counts[emoji] || 0;
|
||||
const active = userReactions.includes(emoji);
|
||||
return `
|
||||
<button class="reaction-btn ${active ? 'active' : ''}" data-emoji="${emoji}">
|
||||
<span class="emoji">${emoji}</span>
|
||||
<span class="count">${count}</span>
|
||||
</button>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
container.querySelectorAll('.reaction-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => toggleReaction(btn));
|
||||
});
|
||||
}
|
||||
|
||||
async function toggleReaction(btn) {
|
||||
if (config.requireAuth && !user) {
|
||||
showAuthPrompt('reactions');
|
||||
return;
|
||||
}
|
||||
|
||||
const emoji = btn.dataset.emoji;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/reader/posts/${config.slug}/reactions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ emoji })
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
showAuthPrompt('reactions');
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
const countEl = btn.querySelector('.count');
|
||||
const current = parseInt(countEl.textContent) || 0;
|
||||
|
||||
if (data.added) {
|
||||
btn.classList.add('active');
|
||||
countEl.textContent = current + 1;
|
||||
} else {
|
||||
btn.classList.remove('active');
|
||||
countEl.textContent = Math.max(0, current - 1);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to toggle reaction', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function initComments() {
|
||||
const section = document.querySelector('.comments');
|
||||
if (!section) return;
|
||||
|
||||
const list = section.querySelector('.comments-list');
|
||||
const formContainer = section.querySelector('.comment-form-container');
|
||||
|
||||
const res = await fetch(`/api/reader/posts/${config.slug}/comments`);
|
||||
const comments = await res.json();
|
||||
|
||||
if (comments && comments.length > 0) {
|
||||
list.innerHTML = comments.map(renderComment).join('');
|
||||
} else {
|
||||
list.innerHTML = '<p class="no-comments">No comments yet. Be the first!</p>';
|
||||
}
|
||||
|
||||
if (user) {
|
||||
formContainer.innerHTML = `
|
||||
<form class="comment-form">
|
||||
<textarea placeholder="Write a comment..." rows="3" required></textarea>
|
||||
<button type="submit">Post Comment</button>
|
||||
</form>
|
||||
`;
|
||||
formContainer.querySelector('form').addEventListener('submit', submitComment);
|
||||
} else {
|
||||
formContainer.innerHTML = `
|
||||
<div class="auth-prompt">
|
||||
<a href="/api/reader/login/github?redirect=${encodeURIComponent(window.location.pathname)}">Sign in</a> to leave a comment
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderComment(comment) {
|
||||
const date = new Date(comment.created_at).toLocaleDateString('en-US', {
|
||||
year: 'numeric', month: 'short', day: 'numeric'
|
||||
});
|
||||
|
||||
return `
|
||||
<div class="comment" data-id="${comment.id}">
|
||||
<div class="comment-header">
|
||||
${comment.avatar_url ? `<img src="${comment.avatar_url}" alt="" class="comment-avatar">` : ''}
|
||||
<span class="comment-author">${escapeHtml(comment.name || 'Anonymous')}</span>
|
||||
<span class="comment-date">${date}</span>
|
||||
</div>
|
||||
<div class="comment-content">${comment.content_html || escapeHtml(comment.content)}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
async function submitComment(e) {
|
||||
e.preventDefault();
|
||||
const form = e.target;
|
||||
const textarea = form.querySelector('textarea');
|
||||
const content = textarea.value.trim();
|
||||
|
||||
if (!content) return;
|
||||
|
||||
const btn = form.querySelector('button');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Posting...';
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/reader/posts/${config.slug}/comments`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ content })
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
showAuthPrompt('comments');
|
||||
return;
|
||||
}
|
||||
|
||||
const comment = await res.json();
|
||||
const list = document.querySelector('.comments-list');
|
||||
const noComments = list.querySelector('.no-comments');
|
||||
if (noComments) noComments.remove();
|
||||
|
||||
list.insertAdjacentHTML('beforeend', renderComment(comment));
|
||||
textarea.value = '';
|
||||
} catch (e) {
|
||||
console.error('Failed to post comment', e);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Post Comment';
|
||||
}
|
||||
}
|
||||
|
||||
function showAuthPrompt(feature) {
|
||||
alert(`Please sign in to use ${feature}`);
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
return { init };
|
||||
})();
|
||||
76
internal/build/templates/base.html
Normal file
76
internal/build/templates/base.html
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<!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}}">
|
||||
<link rel="canonical" href="{{.CanonicalURL}}">
|
||||
|
||||
{{if .NoIndex}}<meta name="robots" content="noindex">{{end}}
|
||||
|
||||
<!-- Open Graph -->
|
||||
<meta property="og:title" content="{{.Title}}">
|
||||
<meta property="og:description" content="{{.Description}}">
|
||||
<meta property="og:type" content="{{.OGType}}">
|
||||
<meta property="og:url" content="{{.CanonicalURL}}">
|
||||
{{if .OGImage}}<meta property="og:image" content="{{.OGImage}}">{{end}}
|
||||
<meta property="og:site_name" content="{{.SiteName}}">
|
||||
|
||||
<!-- Twitter Card -->
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="{{.Title}}">
|
||||
<meta name="twitter:description" content="{{.Description}}">
|
||||
{{if .OGImage}}<meta name="twitter:image" content="{{.OGImage}}">{{end}}
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
{{if .FontURL}}<link rel="stylesheet" href="{{.FontURL}}">{{end}}
|
||||
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--accent: {{with index .Settings "accent_color"}}{{.}}{{else}}#2563eb{{end}};
|
||||
--font-body: {{or .FontFamily "system-ui, -apple-system, sans-serif"}};
|
||||
}
|
||||
</style>
|
||||
|
||||
{{if .StructuredData}}
|
||||
<script type="application/ld+json">{{.StructuredData}}</script>
|
||||
{{end}}
|
||||
</head>
|
||||
<body class="layout-{{with index .Settings "layout"}}{{.}}{{else}}default{{end}} compactness-{{with index .Settings "compactness"}}{{.}}{{else}}cozy{{end}}">
|
||||
<header class="site-header">
|
||||
<a href="/" class="site-name">{{.SiteName}}</a>
|
||||
<nav class="site-nav">
|
||||
<button type="button" id="search-trigger" class="search-trigger">
|
||||
<span>Search</span>
|
||||
<kbd>/</kbd>
|
||||
</button>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
{{template "content" .}}
|
||||
</main>
|
||||
|
||||
<footer class="site-footer">
|
||||
<span>© {{.Year}} {{.SiteName}}</span>
|
||||
{{if .ShowBadge}}<a href="https://writekit.dev" class="powered-by" target="_blank" rel="noopener">Powered by WriteKit</a>{{end}}
|
||||
</footer>
|
||||
|
||||
<div id="search-modal" class="search-modal">
|
||||
<div class="search-modal-backdrop"></div>
|
||||
<div class="search-modal-content">
|
||||
<input type="text" id="search-input" placeholder="Search..." autocomplete="off">
|
||||
<div id="search-results" class="search-results"></div>
|
||||
<div class="search-hint">Press <kbd>ESC</kbd> to close</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/main.js"></script>
|
||||
{{block "scripts" .}}{{end}}
|
||||
</body>
|
||||
</html>
|
||||
34
internal/build/templates/blog.html
Normal file
34
internal/build/templates/blog.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{{define "content"}}
|
||||
<div class="blog">
|
||||
<header class="blog-header">
|
||||
<h1>Posts</h1>
|
||||
</header>
|
||||
|
||||
<section class="posts-list">
|
||||
{{range .Posts}}
|
||||
<article class="post-card">
|
||||
<a href="/posts/{{.Slug}}">
|
||||
<h2 class="post-card-title">{{.Title}}</h2>
|
||||
<time class="post-card-date" datetime="{{.Date.Format "2006-01-02"}}">{{.Date.Format "January 2, 2006"}}</time>
|
||||
{{if .Description}}
|
||||
<p class="post-card-description">{{.Description}}</p>
|
||||
{{end}}
|
||||
</a>
|
||||
</article>
|
||||
{{else}}
|
||||
<p class="no-posts">No posts yet.</p>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
{{if or .PrevPage .NextPage}}
|
||||
<nav class="pagination">
|
||||
{{if .PrevPage}}
|
||||
<a href="{{.PrevPage}}" class="pagination-prev">← Newer</a>
|
||||
{{end}}
|
||||
{{if .NextPage}}
|
||||
<a href="{{.NextPage}}" class="pagination-next">Older →</a>
|
||||
{{end}}
|
||||
</nav>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
34
internal/build/templates/home.html
Normal file
34
internal/build/templates/home.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{{define "content"}}
|
||||
<div class="home">
|
||||
{{with index .Settings "author_bio"}}
|
||||
<section class="profile">
|
||||
{{with index $.Settings "author_avatar"}}
|
||||
<img src="{{.}}" alt="{{$.SiteName}}" class="profile-avatar">
|
||||
{{end}}
|
||||
<p class="profile-bio">{{.}}</p>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
<section class="posts-list">
|
||||
{{range .Posts}}
|
||||
<article class="post-card">
|
||||
<a href="/posts/{{.Slug}}">
|
||||
<h2 class="post-card-title">{{.Title}}</h2>
|
||||
<time class="post-card-date" datetime="{{.Date.Format "2006-01-02"}}">{{.Date.Format "January 2, 2006"}}</time>
|
||||
{{if .Description}}
|
||||
<p class="post-card-description">{{.Description}}</p>
|
||||
{{end}}
|
||||
</a>
|
||||
</article>
|
||||
{{else}}
|
||||
<p class="no-posts">No posts yet.</p>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
{{if .HasMore}}
|
||||
<nav class="pagination">
|
||||
<a href="/posts" class="view-all">View all posts</a>
|
||||
</nav>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
57
internal/build/templates/post.html
Normal file
57
internal/build/templates/post.html
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
{{define "content"}}
|
||||
<article class="post">
|
||||
<header class="post-header">
|
||||
<time class="post-date" datetime="{{.Post.Date.Format "2006-01-02"}}">{{.Post.Date.Format "January 2, 2006"}}</time>
|
||||
<h1 class="post-title">{{.Post.Title}}</h1>
|
||||
{{if .Post.Description}}
|
||||
<p class="post-description">{{.Post.Description}}</p>
|
||||
{{end}}
|
||||
{{if .Post.Tags}}
|
||||
<div class="post-tags">
|
||||
{{range .Post.Tags}}
|
||||
<a href="/tags/{{.}}" class="tag">#{{.}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .Post.CoverImage}}
|
||||
<figure class="post-cover">
|
||||
<img src="{{.Post.CoverImage}}" alt="{{.Post.Title}}" loading="eager" />
|
||||
</figure>
|
||||
{{end}}
|
||||
</header>
|
||||
|
||||
<div class="post-content prose">
|
||||
{{.ContentHTML}}
|
||||
</div>
|
||||
|
||||
{{if .InteractionConfig.ReactionsEnabled}}
|
||||
<section id="reactions" class="reactions" data-slug="{{.Post.Slug}}">
|
||||
<div class="reactions-container"></div>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{if .InteractionConfig.CommentsEnabled}}
|
||||
<section id="comments" class="comments" data-slug="{{.Post.Slug}}">
|
||||
<h3 class="comments-title">Comments</h3>
|
||||
<div class="comments-list"></div>
|
||||
<div class="comment-form-container"></div>
|
||||
</section>
|
||||
{{end}}
|
||||
</article>
|
||||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
{{if or .InteractionConfig.ReactionsEnabled .InteractionConfig.CommentsEnabled}}
|
||||
<script src="/static/js/post.js"></script>
|
||||
<script>
|
||||
WriteKit.init({
|
||||
slug: "{{.Post.Slug}}",
|
||||
reactions: {{.InteractionConfig.ReactionsEnabled}},
|
||||
comments: {{.InteractionConfig.CommentsEnabled}},
|
||||
reactionMode: "{{.InteractionConfig.ReactionMode}}",
|
||||
reactionEmojis: "{{.InteractionConfig.ReactionEmojis}}".split(","),
|
||||
requireAuth: {{.InteractionConfig.ReactionsRequireAuth}}
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
{{end}}
|
||||
139
internal/build/templates/templates.go
Normal file
139
internal/build/templates/templates.go
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var templateFS embed.FS
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"safeHTML": func(s string) template.HTML { return template.HTML(s) },
|
||||
"json": func(v any) string { b, _ := json.Marshal(v); return string(b) },
|
||||
"or": func(a, b any) any {
|
||||
if a != nil && a != "" {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
},
|
||||
}
|
||||
|
||||
var fontURLs = map[string]string{
|
||||
"system": "",
|
||||
"inter": "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap",
|
||||
"georgia": "",
|
||||
"merriweather": "https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&display=swap",
|
||||
"source-serif": "https://fonts.googleapis.com/css2?family=Source+Serif+4:wght@400;600;700&display=swap",
|
||||
"jetbrains-mono": "https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap",
|
||||
}
|
||||
|
||||
var fontFamilies = map[string]string{
|
||||
"system": "system-ui, -apple-system, sans-serif",
|
||||
"inter": "'Inter', system-ui, sans-serif",
|
||||
"georgia": "Georgia, 'Times New Roman', serif",
|
||||
"merriweather": "'Merriweather', Georgia, serif",
|
||||
"source-serif": "'Source Serif 4', Georgia, serif",
|
||||
"jetbrains-mono": "'JetBrains Mono', 'Fira Code', monospace",
|
||||
}
|
||||
|
||||
func GetFontURL(fontKey string) string {
|
||||
if url, ok := fontURLs[fontKey]; ok {
|
||||
return url
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func GetFontFamily(fontKey string) string {
|
||||
if family, ok := fontFamilies[fontKey]; ok {
|
||||
return family
|
||||
}
|
||||
return fontFamilies["system"]
|
||||
}
|
||||
|
||||
var homeTemplate, blogTemplate, postTemplate *template.Template
|
||||
|
||||
func init() {
|
||||
homeTemplate = template.Must(template.New("").Funcs(funcMap).ParseFS(templateFS, "base.html", "home.html"))
|
||||
blogTemplate = template.Must(template.New("").Funcs(funcMap).ParseFS(templateFS, "base.html", "blog.html"))
|
||||
postTemplate = template.Must(template.New("").Funcs(funcMap).ParseFS(templateFS, "base.html", "post.html"))
|
||||
}
|
||||
|
||||
type PageData struct {
|
||||
Title string
|
||||
Description string
|
||||
CanonicalURL string
|
||||
OGType string
|
||||
OGImage string
|
||||
NoIndex bool
|
||||
SiteName string
|
||||
Year int
|
||||
FontURL string
|
||||
FontFamily string
|
||||
StructuredData template.JS
|
||||
Settings map[string]any
|
||||
ShowBadge bool
|
||||
}
|
||||
|
||||
type HomeData struct {
|
||||
PageData
|
||||
Posts []PostSummary
|
||||
HasMore bool
|
||||
}
|
||||
|
||||
type BlogData struct {
|
||||
PageData
|
||||
Posts []PostSummary
|
||||
PrevPage string
|
||||
NextPage string
|
||||
}
|
||||
|
||||
type PostData struct {
|
||||
PageData
|
||||
Post PostDetail
|
||||
ContentHTML template.HTML
|
||||
InteractionConfig map[string]any
|
||||
}
|
||||
|
||||
type PostSummary struct {
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Date time.Time
|
||||
}
|
||||
|
||||
type PostDetail struct {
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
CoverImage string
|
||||
Date time.Time
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func RenderHome(data HomeData) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := homeTemplate.ExecuteTemplate(&buf, "base.html", data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func RenderBlog(data BlogData) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := blogTemplate.ExecuteTemplate(&buf, "base.html", data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func RenderPost(data PostData) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := postTemplate.ExecuteTemplate(&buf, "base.html", data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue