|
1 | | -# README.md |
| 1 | +# Hugo Blog Configuration |
2 | 2 |
|
3 | | -## 📦 Hugo Blog Deployment with GitHub Pages |
| 3 | +Welcome to SeHe's Hugo blog. This project exemplifies modern, automated deployment with Hugo and GitHub Pages. |
4 | 4 |
|
5 | | -This guide explains how to **update**, **build**, and **publish** your Hugo blog to **GitHub Pages**. |
| 5 | +## 🚀 Quick Start |
6 | 6 |
|
7 | | ---- |
| 7 | +1. **Make Changes**: Edit content in `content/` or update configurations as needed. |
| 8 | +2. **Test Locally**: Run `hugo server -D` to preview on `http://localhost:1313`. |
| 9 | +3. **Commit Changes**: Use Git - `git add .`, `git commit -m "message"`, `git push`. |
| 10 | +4. **Deploy**: Automatic via GitHub Actions or manually using provided scripts. |
8 | 11 |
|
9 | | -## 🚀 Prerequisites |
| 12 | +## 🛠 Features |
10 | 13 |
|
11 | | -1. **Hugo Installed:** |
12 | | - - Check with: `hugo version` |
13 | | - - Install: [Hugo Installation Guide](https://gohugo.io/getting-started/installing/) |
| 14 | +- **Automated Deployment**: GitHub Actions pipeline for GitHub Pages. |
| 15 | +- **Pre-commit Hook**: Cleans generated files and prevents accidental commits. |
| 16 | +- **Build Scripts**: Simple PowerShell and Bash scripts for local builds. |
| 17 | +- **Cross-platform**: Compatible with Windows, Linux, and macOS. |
14 | 18 |
|
15 | | -2. **Git Installed:** |
16 | | - - Check with: `git --version` |
17 | | - - Install: [Git Installation Guide](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 19 | +## 📂 Key Files and Directories |
18 | 20 |
|
19 | | -3. **GitHub Repository:** |
20 | | - - A repository with GitHub Pages enabled (either `username.github.io` or a project repo). |
| 21 | +- **content/**: Your markdown content. |
| 22 | +- **static/**: Static assets, images, etc. |
| 23 | +- **layouts/**: Custom layouts and templates. |
| 24 | +- **DEPLOYMENT.md**: Detailed guide on deploying your site. |
21 | 25 |
|
22 | | -4. **Remote Repository Set:** |
23 | | - - Check with: `git remote -v` |
24 | | - - If not set: |
25 | | - ```bash |
26 | | - git remote add origin https://github.com/username/repository.git |
27 | | - ``` |
| 26 | +## 🛠 Build & Deploy |
28 | 27 |
|
29 | | ---- |
| 28 | +### Build Locally |
| 29 | +- **Windows**: Run `./build.ps1`. |
| 30 | +- **Linux/macOS**: Run `./build.sh`. |
30 | 31 |
|
31 | | -## 🔄 Update Your Site |
| 32 | +### Deployment |
| 33 | +For automatic deployment, ensure GitHub Pages is set to build from GitHub Actions: |
| 34 | +1. Go to your repository settings on GitHub. |
| 35 | +2. Navigate to **Pages** and set the source to **GitHub Actions**. |
| 36 | +3. Simply push to `main` to deploy. |
32 | 37 |
|
33 | | -1. **Pull the Latest Changes (Optional):** |
34 | | - ```bash |
35 | | - git pull origin main |
36 | | - ``` |
| 38 | +## 🛡️ Troubleshooting |
37 | 39 |
|
38 | | -2. **Make Changes:** |
39 | | - - Add or edit content in `content/` |
40 | | - - Update config in `config.toml` |
| 40 | +- **CSS/JS Issues**: Check paths and ensure assets in `static/`. |
| 41 | +- **Build Errors**: Use `hugo --verbose` to diagnose issues. |
| 42 | +- **Deployment Errors**: Verify Pages configuration and logs in GitHub Actions. |
41 | 43 |
|
42 | | -3. **Check Changes Locally:** |
43 | | - ```bash |
44 | | - hugo server -D |
45 | | - ``` |
46 | | - - Open `http://localhost:1313` in your browser. |
47 | | - |
48 | | ---- |
49 | | - |
50 | | -## 🛠️ Build the Site |
51 | | - |
52 | | -When you're ready to deploy: |
53 | | -
|
54 | | -1. **Clean and Build the Site:** |
55 | | - ```bash |
56 | | - hugo --minify |
57 | | - ``` |
58 | | - - This generates the site in the `public/` folder. |
59 | | -
|
60 | | -2. **Verify Output:** |
61 | | - Since `hugo server --source public` does not work as expected, open the `public/` folder directly in a browser: |
62 | | - - On Linux: |
63 | | - ```bash |
64 | | - xdg-open public/index.html |
65 | | - ``` |
66 | | - - On Windows: |
67 | | - ```bash |
68 | | - start public/index.html |
69 | | - ``` |
70 | | - - On macOS: |
71 | | - ```bash |
72 | | - open public/index.html |
73 | | - ``` |
74 | | -
|
75 | | ---- |
76 | | -
|
77 | | -## 🌐 Deploy to GitHub Pages |
78 | | -
|
79 | | -### Option 1: Deploy via `gh-pages` Branch (Recommended) |
80 | | -
|
81 | | -1. **Commit Your Changes:** |
82 | | - ```bash |
83 | | - git add . |
84 | | - git commit -m "Update blog content" |
85 | | - git push origin main |
86 | | - ``` |
87 | | -
|
88 | | -2. **Push `public/` Folder to `gh-pages`:** |
89 | | - If you encounter an error like "non-fast-forward": |
90 | | - ```bash |
91 | | - git pull --rebase origin gh-pages |
92 | | - git subtree push --prefix public origin gh-pages |
93 | | - ``` |
94 | | - Or force push if you're sure to overwrite: |
95 | | - ```bash |
96 | | - git push origin gh-pages --force |
97 | | - ``` |
98 | | - |
99 | | -3. **Verify Deployment:** |
100 | | - - Go to: `https://username.github.io/` or `https://username.github.io/repository/` |
101 | | - |
102 | | ---- |
103 | | - |
104 | | -### Option 2: Deploy Directly (If Repo Is `username.github.io`) |
105 | | - |
106 | | -1. **Commit and Push:** |
107 | | - ```bash |
108 | | - git add . |
109 | | - git commit -m "Update blog" |
110 | | - git push origin main |
111 | | - ``` |
112 | | - |
113 | | -2. **GitHub Pages Settings:** |
114 | | - - Go to **Settings → Pages**. |
115 | | - - Set **Source** to `main` branch (or `gh-pages` if using that). |
116 | | - |
117 | | -3. **Visit Your Site:** |
118 | | - - `https://username.github.io/` |
119 | | - |
120 | | ---- |
121 | | - |
122 | | -## 🧹 Clean Build (Optional) |
123 | | - |
124 | | -If things don't work as expected: |
125 | | -
|
126 | | -1. **Clear `public/` Folder:** |
127 | | - ```bash |
128 | | - rm -rf public/ |
129 | | - hugo --minify |
130 | | - ``` |
131 | | -
|
132 | | -2. **Force Push:** |
133 | | - ```bash |
134 | | - git add . |
135 | | - git commit -m "Clean build" |
136 | | - git push origin main --force |
137 | | - ``` |
138 | | -
|
139 | | ---- |
140 | | -
|
141 | | -## 📝 Troubleshooting |
142 | | -
|
143 | | -- **Page Not Updating?** |
144 | | - - Clear browser cache. |
145 | | - - Verify `gh-pages` branch is up-to-date. |
146 | | -
|
147 | | -- **Build Errors?** |
148 | | - - Run `hugo` without `--minify` to see detailed errors. |
149 | | -
|
150 | | -- **Push Rejected (non-fast-forward)?** |
151 | | - - Pull the latest changes first: |
152 | | - ```bash |
153 | | - git pull --rebase origin gh-pages |
154 | | - git subtree push --prefix public origin gh-pages |
155 | | - ``` |
156 | | - - Or force push if necessary: |
157 | | - ```bash |
158 | | - git push origin gh-pages --force |
159 | | - ``` |
160 | | -
|
161 | | -- **404 Errors on Subpages?** |
162 | | - - Make sure `baseURL` in `config.toml` is correct. |
163 | | -
|
164 | | ---- |
165 | | -
|
166 | | -## 📚 Useful Commands |
167 | | -
|
168 | | -```bash |
169 | | -# Start local server |
170 | | -hugo server -D |
171 | | -
|
172 | | -# Build site |
173 | | -hugo --minify |
174 | | -
|
175 | | -# Deploy to gh-pages |
176 | | -git subtree push --prefix public origin gh-pages |
177 | | -
|
178 | | -# Clean public folder |
179 | | -rm -rf public/ |
180 | | -
|
181 | | -# Fix non-fast-forward error |
182 | | -git pull --rebase origin gh-pages |
183 | | -git subtree push --prefix public origin gh-pages |
184 | | -``` |
185 | | -
|
186 | | -Happy blogging! 🚀 |
| 44 | +## 🎉 Enjoy Blogging! |
| 45 | +Your site is configured to deploy effortlessly. Focus on writing while the automation handles the details. |
187 | 46 |
|
0 commit comments