Skip to content

Commit 46fcc65

Browse files
committed
fixing theme validation issues
1 parent fa579e1 commit 46fcc65

File tree

5 files changed

+244
-23
lines changed

5 files changed

+244
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
# Go workspace file
2121
go.work
2222
go.work.sum
23+

exampleSite/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
baseURL = "http://example.org"
2+
title = "PKB Theme Demo"
3+
theme = "github.com/stradichenko/PKB-theme"
4+
5+
[module]
6+
[[module.imports]]
7+
path = "github.com/stradichenko/PKB-theme"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Hello World"
3+
date: 2025-03-17T22:41:47Z
4+
draft: false
5+
---
6+
7+
Welcome to your PKB Theme demo!

theme.toml

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
name = 'Theme name'
1+
name = 'PKB Theme'
22
license = 'MIT'
3-
licenselink = 'https://github.com/owner/repo/LICENSE'
4-
description = 'Theme description'
3+
licenselink = 'https://github.com/stradichenko/PKB-theme/blob/main/LICENSE'
4+
description = 'Modern documentation theme for Hugo'
55

6-
# The home page of the theme, where the source can be found
7-
homepage = 'https://github.com/owner/repo'
6+
# Required for validation
7+
[author]
8+
name = 'Your Name'
9+
homepage = 'https://your-website.com'
810

9-
# If you have a running demo of the theme
10-
demosite = 'https://owner.github.io/repo'
11+
# Remove one of these conflicting sections:
12+
# EITHER this (single author):
13+
[author]
14+
name = "Your Name"
15+
homepage = "https://your-website.com"
1116

12-
# Taxonomy terms
13-
tags = ['blog', 'company']
14-
features = ['some', 'awesome', 'features']
17+
# OR this (multiple authors):
18+
# authors = [
19+
# {name = 'Name 1', homepage = 'https://site1.com'},
20+
# {name = 'Name 2', homepage = 'https://site2.com'}
21+
# ]
1522

16-
# If the theme has multiple authors
17-
authors = [
18-
{name = 'Name of author', homepage = 'Website of author'},
19-
{name = 'Name of author', homepage = 'Website of author'}
20-
]
23+
# Demo configuration
24+
homepage = 'https://github.com/stradichenko/PKB-theme'
25+
demosite = 'https://stradichenko.github.io/PKB-theme/'
2126

22-
# If the theme has a single author
23-
[author]
24-
name = 'Your name'
25-
homepage = 'Your website'
27+
# Taxonomy
28+
tags = ['documentation', 'knowledge-base']
29+
features = ['responsive', 'search']
2630

27-
# If porting an existing theme
31+
# Original theme attribution (if applicable)
2832
[original]
29-
author = 'Name of original author'
30-
homepage = 'Website of original author'
31-
repo = 'https://github.com/owner/repo'
33+
author = 'Original Author Name'
34+
homepage = 'https://original-theme-site.com'
35+
repo = 'https://github.com/original/repo'

validate-theme.sh

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#!/bin/bash
2+
3+
# Validate Hugo Theme Repository Configuration
4+
# Run from the theme's root directory
5+
6+
# Color codes
7+
RED='\033[0;31m'
8+
GREEN='\033[0;32m'
9+
YELLOW='\033[1;33m'
10+
NC='\033[0m' # No Color
11+
12+
passed_checks=0
13+
total_checks=0
14+
15+
function check_required_file() {
16+
((total_checks++))
17+
if [[ -f "$1" ]]; then
18+
echo -e "${GREEN}✓ Found: $1${NC}"
19+
((passed_checks++))
20+
return 0
21+
else
22+
echo -e "${RED}✗ Missing: $1${NC}"
23+
return 1
24+
fi
25+
}
26+
27+
function validate_theme_toml() {
28+
((total_checks++))
29+
local required_fields=("name" "license")
30+
local missing_fields=()
31+
32+
if [[ ! -f "theme.toml" ]]; then
33+
echo -e "${RED}✗ Missing theme.toml${NC}"
34+
return 1
35+
fi
36+
37+
# Check required top-level fields
38+
for field in "${required_fields[@]}"; do
39+
if ! grep -q "^$field =" theme.toml; then
40+
missing_fields+=("$field")
41+
fi
42+
done
43+
44+
# Check author information
45+
if ! grep -q "^\[author\]" theme.toml && ! grep -q "^authors = \[" theme.toml; then
46+
missing_fields+=("author(s)")
47+
fi
48+
49+
if [[ ${#missing_fields[@]} -gt 0 ]]; then
50+
echo -e "${RED}✗ theme.toml missing: ${missing_fields[*]}${NC}"
51+
return 1
52+
else
53+
echo -e "${GREEN}✓ theme.toml valid${NC}"
54+
((passed_checks++))
55+
return 0
56+
fi
57+
}
58+
function validate_go_mod() {
59+
((total_checks++))
60+
if [[ ! -f "go.mod" ]]; then
61+
echo -e "${RED}✗ Missing go.mod${NC}"
62+
return 1
63+
fi
64+
65+
if grep -q "^module github.com/stradichenko/PKB-theme" go.mod; then
66+
echo -e "${GREEN}✓ go.mod has correct module path${NC}"
67+
((passed_checks++))
68+
return 0
69+
else
70+
echo -e "${RED}✗ Invalid module path in go.mod${NC}"
71+
return 1
72+
fi
73+
}
74+
75+
function validate_directory_structure() {
76+
local required_dirs=("archetypes" "layouts" "static" "assets")
77+
local missing_dirs=()
78+
((total_checks++))
79+
80+
for dir in "${required_dirs[@]}"; do
81+
if [[ ! -d "$dir" ]]; then
82+
missing_dirs+=("$dir")
83+
fi
84+
done
85+
86+
if [[ ${#missing_dirs[@]} -gt 0 ]]; then
87+
echo -e "${YELLOW}⚠ Missing directories: ${missing_dirs[*]}${NC}"
88+
return 1
89+
else
90+
echo -e "${GREEN}✓ All required directories present${NC}"
91+
((passed_checks++))
92+
return 0
93+
fi
94+
}
95+
96+
function validate_version_tags() {
97+
((total_checks++))
98+
local tags=$(git tag -l)
99+
local semver_tags=()
100+
101+
while IFS= read -r tag; do
102+
if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
103+
semver_tags+=("$tag")
104+
fi
105+
done <<< "$tags"
106+
107+
if [[ ${#semver_tags[@]} -eq 0 ]]; then
108+
echo -e "${YELLOW}⚠ No semantic version tags found (e.g., v1.0.0)${NC}"
109+
return 1
110+
else
111+
echo -e "${GREEN}✓ Found semantic version tags: ${semver_tags[*]}${NC}"
112+
((passed_checks++))
113+
return 0
114+
fi
115+
}
116+
117+
function validate_example_site() {
118+
((total_checks++))
119+
if [[ ! -d "exampleSite" ]]; then
120+
echo -e "${YELLOW}⚠ Missing exampleSite directory${NC}"
121+
return 1
122+
fi
123+
124+
local example_checks=0
125+
check_required_file "exampleSite/config.toml" && ((example_checks++))
126+
[[ -d "exampleSite/content" ]] && ((example_checks++))
127+
128+
if [[ $example_checks -eq 2 ]]; then
129+
echo -e "${GREEN}✓ exampleSite configuration valid${NC}"
130+
((passed_checks++))
131+
return 0
132+
else
133+
echo -e "${YELLOW}⚠ Incomplete exampleSite configuration${NC}"
134+
return 1
135+
fi
136+
}
137+
138+
function validate_readme() {
139+
((total_checks++))
140+
local check_passed=1
141+
142+
if [[ ! -f "README.md" ]]; then
143+
echo -e "${RED}✗ Missing README.md${NC}"
144+
return 1
145+
fi
146+
147+
grep -q "hugo mod init" README.md && \
148+
grep -q "module.imports" README.md && \
149+
grep -q "hugo mod get" README.md
150+
151+
if [[ $? -eq 0 ]]; then
152+
echo -e "${GREEN}✓ README contains module installation instructions${NC}"
153+
((passed_checks++))
154+
return 0
155+
else
156+
echo -e "${YELLOW}⚠ README missing module installation instructions${NC}"
157+
return 1
158+
fi
159+
}
160+
161+
function validate_environment() {
162+
echo -e "\n${YELLOW}=== Environment Validation ===${NC}"
163+
164+
# Check for required commands
165+
local required_commands=("git" "hugo" "grep")
166+
for cmd in "${required_commands[@]}"; do
167+
if ! command -v $cmd &> /dev/null; then
168+
echo -e "${RED}✗ Missing required command: $cmd${NC}"
169+
exit 1
170+
fi
171+
done
172+
173+
# Verify we're in a git repository
174+
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
175+
echo -e "${RED}✗ Not in a git repository${NC}"
176+
exit 1
177+
fi
178+
}
179+
180+
function main() {
181+
validate_environment
182+
183+
echo -e "\n${YELLOW}=== Theme Configuration Validation ===${NC}"
184+
validate_theme_toml
185+
validate_go_mod
186+
validate_directory_structure
187+
validate_version_tags
188+
validate_example_site
189+
validate_readme
190+
191+
echo -e "\n${YELLOW}=== Validation Summary ===${NC}"
192+
echo -e "Passed checks: ${GREEN}$passed_checks${NC} / $total_checks"
193+
194+
if [[ $passed_checks -eq $total_checks ]]; then
195+
echo -e "${GREEN}✓ All critical checks passed!${NC}"
196+
else
197+
echo -e "${RED}✗ Some checks failed. Review the output above.${NC}"
198+
exit 1
199+
fi
200+
}
201+
202+
main

0 commit comments

Comments
 (0)