Skip to content

Commit 9ac9ef9

Browse files
authored
Merge pull request #1293 from python-discord/feat/timeline-from-yaml
Markdown + YAML for the timeline
2 parents fec87a6 + 10f3f6a commit 9ac9ef9

File tree

69 files changed

+783
-994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+783
-994
lines changed

pydis_site/apps/home/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# The "home" app
22

33
This Django application takes care of serving the homepage of our website, that
4-
is, the first page that you see when you open pythondiscord.com. It also
5-
manages the timeline page showcasing the history of our community.
4+
is, the first page that you see when you open pythondiscord.com.
65

76
## Directory structure
87

pydis_site/apps/home/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from django_distill import distill_path
22

3-
from .views import HomeView, timeline
3+
from .views import HomeView
44

55
app_name = 'home'
66
urlpatterns = [
77
distill_path('', HomeView.as_view(), name='home'),
8-
distill_path('timeline/', timeline, name="timeline"),
98
]

pydis_site/apps/home/views.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,3 @@ def get(self, request: WSGIRequest) -> HttpResponse:
153153
"""Collect repo data and render the homepage view."""
154154
repo_data = self._get_repo_data()
155155
return render(request, "home/index.html", {"repo_data": repo_data})
156-
157-
158-
def timeline(request: WSGIRequest) -> HttpResponse:
159-
"""Render timeline view."""
160-
return render(request, 'home/timeline.html')

pydis_site/apps/timeline/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# The "timeline" app
2+
3+
The [timeline page](https://www.pythondiscord.com/timeline/) on our website is
4+
powered by this Django application.
5+
6+
## The entries
7+
8+
Timeline entries are written in markdown files with YAML frontmatter under the
9+
`entries` directory.
10+
11+
Each file represents a timeline entry. The file names have the format
12+
`<date>_<name>.md`, where:
13+
- `date` is in `YYYY-MM-DD` for easy sorting of files in directory listings,
14+
also used for sorting of the entries displayed on the timeline page.
15+
- `name` is an arbitrary slug in `kebab-case`, used for linking to individual
16+
timeline entries on the page, which will be set in the `id` attribute for each
17+
timeline item.
18+
19+
Each file contains:
20+
- A YAML frontmatter, which defines some metadata shown next to each entry in
21+
the timeline, including:
22+
- `date`: User-facing date label.
23+
- `icon`: The CSS class used for the icon, e.g. "fa fa-snowflake". Set to
24+
`pydis` to use the pydis logo image.
25+
- `icon_color`: The CSS class that sets the background color of the icon, e.g.
26+
"pastel-red". List of available colors can be found in [the CSS
27+
file](../../static/css/timeline/timeline.css). This can be omitted if the
28+
pydis logo is used.
29+
- Markdown content.
30+
31+
32+
## Directory structure
33+
34+
The app has a single view in `views.py` that renders the template using the list
35+
of parsed entries from `apps.py`, which reads the markdown files on startup.
36+
This is a standard Django view, mounted in `urls.py` as usual.
37+
38+
The `tests` directory validates that the page renders successfully as expected.
39+
If you made changes to the app and are looking for guidance on adding new tests,
40+
the [Django tutorial introducing automated
41+
testing](https://docs.djangoproject.com/en/dev/intro/tutorial05/) is a good
42+
place to start.
43+
44+
This application does not use the database and as such does not have models nor
45+
migrations.

pydis_site/apps/timeline/__init__.py

Whitespace-only changes.

pydis_site/apps/timeline/apps.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from pathlib import Path
2+
3+
from django.apps import AppConfig
4+
import frontmatter
5+
import markdown
6+
7+
from pydis_site import settings
8+
9+
10+
ENTRIES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "timeline", "entries")
11+
12+
13+
class TimelineConfig(AppConfig):
14+
"""AppConfig instance for Timeline app."""
15+
16+
name = 'pydis_site.apps.timeline'
17+
18+
def ready(self) -> None:
19+
"""Fetch all the timeline entries."""
20+
self.entries = []
21+
22+
for path in ENTRIES_PATH.rglob("*.md"):
23+
metadata, content = frontmatter.parse(path.read_text(encoding="utf-8"))
24+
25+
md = markdown.Markdown()
26+
html = str(md.convert(content))
27+
28+
# Strip `.md` file extension from filename and split it into the
29+
# date (for sorting) and slug (for linking).
30+
key, slug = path.name[:-3].split("_")
31+
32+
icon_color = metadata.get("icon_color")
33+
# Use the pydis blurple as the default background color.
34+
if not icon_color or metadata["icon"] == "pydis":
35+
icon_color = "has-background-primary"
36+
37+
entry = {
38+
"key": key,
39+
"slug": slug,
40+
"title": metadata["title"],
41+
"date": metadata["date"],
42+
"icon": metadata["icon"],
43+
"icon_color": icon_color,
44+
"content": html,
45+
}
46+
47+
self.entries.append(entry)
48+
49+
# Sort the entries in reverse-chronological order.
50+
self.entries.sort(key=lambda e: e['key'], reverse=True)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Python Discord is created
3+
date: Jan 8th, 2017
4+
icon: pydis
5+
---
6+
7+
**Joe Banks** becomes one of the owners around 3 days after it is created, and
8+
**Leon Sandøy** (lemon) joins the owner team later in the year, when the
9+
community has around 300 members.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Python Discord hits 1,000 members
3+
date: Nov 10th, 2017
4+
icon: fa fa-users
5+
icon_color: pastel-dark-blue
6+
---
7+
8+
Our main source of new users at this point is a post on Reddit that happens to
9+
get very good SEO. We are one of the top 10 search engine hits for the search
10+
term "python discord".
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Our logo is born. Thanks @Aperture!
3+
date: Feb 3rd, 2018
4+
icon: pydis
5+
---
6+
7+
<p style="background-color: #7289DA; border-radius: 10px;">
8+
<img style="padding-right: 20px;" src="https://raw.githubusercontent.com/python-discord/branding/main/logos/logo_banner/logo_site_banner.svg">
9+
</p>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: PyDis hits 2,000 members; pythondiscord.com and @Python are live
3+
date: Mar 4th, 2018
4+
icon: fa fa-users
5+
icon_color: pastel-dark-blue
6+
---
7+
8+
The public moderation bot we're using at the time, Rowboat, announces it will be
9+
shutting down. We decide that we'll write our own bot to handle moderation, so
10+
that we can have more control over its features. We also buy a domain and start
11+
making a website in Flask.

0 commit comments

Comments
 (0)