Skip to content

Commit

Permalink
new idx
Browse files Browse the repository at this point in the history
  • Loading branch information
elimelt committed Jan 1, 2025
1 parent a231a43 commit 2e2d02a
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 17 deletions.
7 changes: 0 additions & 7 deletions index.md

This file was deleted.

101 changes: 100 additions & 1 deletion scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = "<h2>Recent Notes</h2>\n<ul class='recent-posts'>"
for page in recent_pages:
page_url = f"/{page.path.with_suffix('.html')}"
date_str = page.modified_date.strftime('%Y-%m-%d')
recent_content += f'''
<li>
<a href="{page_url}">{page.title}</a>
<span class="date">{date_str}</span>
{f'<span class="category">{page.category}</span>' if page.category else ''}
</li>'''
recent_content += "</ul>"

# Generate categories section
categories_content = "<h2>Categories</h2>\n<ul class='categories-list'>"
for category, pages in sorted(self.categories.items()):
category_url = f"/categories/{quote(category.lower())}.html"
categories_content += f'''
<li>
<a href="{category_url}">{category}</a>
<span class="count">({len(pages)})</span>
</li>'''
categories_content += "</ul>"

# 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 = "<h2>Popular Tags</h2>\n<div class='tags-cloud'>"
for tag, count in popular_tags:
tag_url = f"/tags/{quote(tag.lower())}.html"
tags_content += f'<a href="{tag_url}" class="tag-{min(count, 5)}">{tag} <span>({count})</span></a>'
tags_content += "</div>"

# 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"""
<div class="landing-stats">
<div class="stat-item">
<span class="stat-value">{total_notes}</span>
<span class="stat-label">Notes</span>
</div>
<div class="stat-item">
<span class="stat-value">{total_categories}</span>
<span class="stat-label">Categories</span>
</div>
<div class="stat-item">
<span class="stat-value">{total_tags}</span>
<span class="stat-label">Tags</span>
</div>
</div>
<div class="landing-grid">
<div class="recent-section">
{recent_content}
</div>
<div class="categories-section">
{categories_content}
</div>
<div class="tags-section">
{tags_content}
</div>
</div>
"""

# 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)
Expand Down
91 changes: 83 additions & 8 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index</title>

<title>My Digital Garden</title>
<meta name="description" content="A collection of my digital notes and thoughts">
<style>
:root {
--text-color: #2c3e50;
Expand Down Expand Up @@ -175,17 +175,92 @@
<div class="breadcrumbs">
<a href="/index.html">Home</a>
</div>
<h1>Index</h1>
<h1>My Digital Garden</h1>
<div class="meta">
<span>Last modified: 2025-01-01</span>

</div>
<div class="content">
<h1 id="test">Test</h1>
<p>This is a test index.md file.</p>
<pre><code class="language-java">// Test code block
System.out.println(&quot;Hello, world!&quot;);
</code></pre>

<div class="landing-stats">
<div class="stat-item">
<span class="stat-value">146</span>
<span class="stat-label">Notes</span>
</div>
<div class="stat-item">
<span class="stat-value">0</span>
<span class="stat-label">Categories</span>
</div>
<div class="stat-item">
<span class="stat-value">0</span>
<span class="stat-label">Tags</span>
</div>
</div>
<div class="landing-grid">
<div class="recent-section">
<h2>Recent Notes</h2>
<ul class='recent-posts'>
<li>
<a href="/teaching/modern-java/collections-and-records.html">Collections And Records</a>
<span class="date">2024-12-08</span>

</li>
<li>
<a href="/teaching/modern-java/lambdas-and-streams.html">Lambdas And Streams</a>
<span class="date">2024-12-08</span>

</li>
<li>
<a href="/linear-algebra/python-cheatsheet.html">Python Cheatsheet</a>
<span class="date">2024-12-08</span>

</li>
<li>
<a href="/performance-engineering/efficiently-implementing-state-pattern-JVM.html">Efficiently Implementing State Pattern Jvm</a>
<span class="date">2024-12-08</span>

</li>
<li>
<a href="/distributed-systems/disconnected-operation.html">Disconnected Operation</a>
<span class="date">2024-12-08</span>

</li>
<li>
<a href="/linear-algebra/elementry-linear-algebra.html">Elementry Linear Algebra</a>
<span class="date">2024-11-14</span>

</li>
<li>
<a href="/linear-algebra/cheatsheet.html">Cheatsheet</a>
<span class="date">2024-11-09</span>

</li>
<li>
<a href="/algorithms/linear-programming.html">Linear Programming</a>
<span class="date">2024-05-25</span>

</li>
<li>
<a href="/distributed-systems/dynamo-db.html">Dynamo Db</a>
<span class="date">2024-05-24</span>

</li>
<li>
<a href="/algorithms/network-flows.html">Network Flows</a>
<span class="date">2024-05-24</span>

</li></ul>
</div>
<div class="categories-section">
<h2>Categories</h2>
<ul class='categories-list'></ul>
</div>
<div class="tags-section">
<h2>Popular Tags</h2>
<div class='tags-cloud'></div>
</div>
</div>

</div>

</main>
Expand Down
101 changes: 100 additions & 1 deletion site/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = "<h2>Recent Notes</h2>\n<ul class='recent-posts'>"
for page in recent_pages:
page_url = f"/{page.path.with_suffix('.html')}"
date_str = page.modified_date.strftime('%Y-%m-%d')
recent_content += f'''
<li>
<a href="{page_url}">{page.title}</a>
<span class="date">{date_str}</span>
{f'<span class="category">{page.category}</span>' if page.category else ''}
</li>'''
recent_content += "</ul>"

# Generate categories section
categories_content = "<h2>Categories</h2>\n<ul class='categories-list'>"
for category, pages in sorted(self.categories.items()):
category_url = f"/categories/{quote(category.lower())}.html"
categories_content += f'''
<li>
<a href="{category_url}">{category}</a>
<span class="count">({len(pages)})</span>
</li>'''
categories_content += "</ul>"

# 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 = "<h2>Popular Tags</h2>\n<div class='tags-cloud'>"
for tag, count in popular_tags:
tag_url = f"/tags/{quote(tag.lower())}.html"
tags_content += f'<a href="{tag_url}" class="tag-{min(count, 5)}">{tag} <span>({count})</span></a>'
tags_content += "</div>"

# 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"""
<div class="landing-stats">
<div class="stat-item">
<span class="stat-value">{total_notes}</span>
<span class="stat-label">Notes</span>
</div>
<div class="stat-item">
<span class="stat-value">{total_categories}</span>
<span class="stat-label">Categories</span>
</div>
<div class="stat-item">
<span class="stat-value">{total_tags}</span>
<span class="stat-label">Tags</span>
</div>
</div>
<div class="landing-grid">
<div class="recent-section">
{recent_content}
</div>
<div class="categories-section">
{categories_content}
</div>
<div class="tags-section">
{tags_content}
</div>
</div>
"""

# 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)
Expand Down

0 comments on commit 2e2d02a

Please sign in to comment.