diff --git a/index.md b/index.md deleted file mode 100644 index c0ca341..0000000 --- a/index.md +++ /dev/null @@ -1,7 +0,0 @@ -# Test - -This is a test index.md file. -```java -// Test code block -System.out.println("Hello, world!"); -``` diff --git a/scripts/build.py b/scripts/build.py index 2cd36de..2e5c26a 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -172,7 +172,11 @@ def _copy_assets(self) -> None: output_path.chmod(0o644) def _generate_special_pages(self) -> None: - """Generate special pages like category index and tag index""" + """Generate special pages like main index, category index and tag index""" + # Generate main index + self._generate_main_index() + + # Generate categories and tags pages # Generate categories index if self.categories: categories_content = self._render_categories_index() @@ -326,6 +330,101 @@ def _generate_navigation(self, current_page: Page) -> str: return '\n'.join(nav_items) + def _generate_main_index(self) -> None: + """Generate the main index.html page""" + # Get recent pages (excluding special pages) + regular_pages = [p for p in self.pages.values() + if not (p.is_index or str(p.path).startswith(('categories/', 'tags/')))] + recent_pages = sorted(regular_pages, + key=lambda p: p.modified_date, + reverse=True)[:10] # Show 10 most recent + + # Generate recent posts section + recent_content = "

Recent Notes

\n" + + # Generate categories section + categories_content = "

Categories

\n" + + # Generate popular tags section (show top 20 most used tags) + tag_counts = {tag: len(pages) for tag, pages in self.tags.items()} + popular_tags = sorted(tag_counts.items(), key=lambda x: (-x[1], x[0]))[:20] + + tags_content = "

Popular Tags

\n
" + for tag, count in popular_tags: + tag_url = f"/tags/{quote(tag.lower())}.html" + tags_content += f'{tag} ({count})' + tags_content += "
" + + # Calculate some statistics + total_notes = len(regular_pages) + total_categories = len(self.categories) + total_tags = len(self.tags) + + # Create the landing page content + content = f""" +
+
+ {total_notes} + Notes +
+
+ {total_categories} + Categories +
+
+ {total_tags} + Tags +
+
+
+
+ {recent_content} +
+
+ {categories_content} +
+
+ {tags_content} +
+
+ """ + + # Create the index page + index_page = Page( + title="My Digital Garden", + path=Path("index.md"), + content=content, + modified_date=datetime.now(), + category=None, + tags=[], + description="A collection of my digital notes and thoughts", + is_index=True + ) + + # Generate the HTML + output_path = self.output_dir / 'index.html' + html_content = self._render_template(index_page) + output_path.write_text(html_content, encoding='utf-8') + output_path.chmod(0o644) + def _render_template(self, page: Page) -> str: """Render HTML template for a page""" navigation = self._generate_navigation(page) diff --git a/site/index.html b/site/index.html index 90ee658..df2505c 100644 --- a/site/index.html +++ b/site/index.html @@ -3,8 +3,8 @@ - Index - + My Digital Garden +