Skip to content

Commit

Permalink
Merge pull request #57 from collove/feature/blog
Browse files Browse the repository at this point in the history
Blog Section Added fixes #55
  • Loading branch information
lnxpy authored Jul 31, 2022
2 parents d00cd21 + b4016d9 commit d521bce
Show file tree
Hide file tree
Showing 26 changed files with 347 additions and 16 deletions.
Empty file added blog/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin

# Register your models here.

from .models import Blog, Tag

admin.site.register(Blog)
admin.site.register(Tag)
6 changes: 6 additions & 0 deletions blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
24 changes: 24 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.0.6 on 2022-07-31 09:07

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Blog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('body', models.TextField()),
('slug', models.SlugField(unique=True)),
('published_at', models.DateTimeField(editable=False)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.0.6 on 2022-07-31 09:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='blog',
name='absract',
field=models.TextField(default=' '),
preserve_default=False,
),
migrations.AlterField(
model_name='blog',
name='published_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='blog',
name='slug',
field=models.SlugField(editable=False, unique=True),
),
]
18 changes: 18 additions & 0 deletions blog/migrations/0003_rename_absract_blog_abstract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.6 on 2022-07-31 09:24

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('blog', '0002_blog_absract_alter_blog_published_at_alter_blog_slug'),
]

operations = [
migrations.RenameField(
model_name='blog',
old_name='absract',
new_name='abstract',
),
]
26 changes: 26 additions & 0 deletions blog/migrations/0004_tag_blog_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.0.6 on 2022-07-31 10:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0003_rename_absract_blog_abstract'),
]

operations = [
migrations.CreateModel(
name='Tag',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.TextField()),
],
),
migrations.AddField(
model_name='blog',
name='tags',
field=models.ManyToManyField(blank=True, to='blog.tag'),
),
]
Empty file added blog/migrations/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models
from django.utils.text import slugify


class Tag(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()

def __str__(self) -> str: return self.name


class Blog(models.Model):
title = models.CharField(max_length=255)
abstract = models.TextField()
body = models.TextField()
tags = models.ManyToManyField(Tag, blank=True)
slug = models.SlugField(unique=True, editable=False)
published_at = models.DateTimeField(auto_now=True)

def __str__(self) -> str: return self.title

def save(self, *args, **kwargs):
self.slug = slugify(self.title, allow_unicode=True)
return super().save(*args, **kwargs)
49 changes: 49 additions & 0 deletions blog/templates/blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends '_base.html' %}
{% load static %}
{% load markdown_extras %}

{% block title %}{{blog.title}}{% endblock %}

{% block metas %}
<!-- Primary Meta Tags -->
<meta name="title" content="{{blog.title}}">
<meta name="description"
content="{{blog.abstract}}">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="{% url 'blog' blog.slug %}">
<meta property="og:title"
content="{{blog.title}}">
<meta property="og:description"
content="{{blog.abstract}}">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="{% url 'blog' blog.slug %}">
<meta property="twitter:title"
content="{{blog.title}}">
<meta property="twitter:description"
content="{{blog.abstract}}">
{% endblock %}

{% block addon_link %}
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
{% endblock %}

{% block blog_active %}active{% endblock %}

{% block content %}
<section class="p-5">
<div class="container d-flex justify-content-center">
<div class="col-md-9">
<h1 class="title">{{blog.title}}</h1>
<p class="text-muted">Published on {{blog.published_at | date:'M d, Y'}} &#183;
{% for tag in blog.tags.all %}
<span class="badge me-1 bg-black">{{tag.name}}</span>
{% endfor %%}
</p>
<h5 class="text-muted mt-4 mb-4 abstract">{{blog.abstract}}</h5>
<div class="body">{{blog.body | markdown | safe}}</div>
</div>
</div>
</section>
{% endblock %}
66 changes: 66 additions & 0 deletions blog/templates/blogs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{% extends '_base.html' %}
{% load static %}

{% block title %}PasteMe - Blogs{% endblock %}

{% block blog_active %}active{% endblock %}

{% block metas %}
<!-- Primary Meta Tags -->
<meta name="title" content="PasteMe - Blogs">
<meta name="description"
content="Follow the feed and keep up with the tech.">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="{% url 'blogs' %}">
<meta property="og:title"
content="PasteMe - Blogs">
<meta property="og:description"
content="Follow the feed and keep up with the tech.">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="{% url 'blogs' %}">
<meta property="twitter:title"
content="PasteMe - Blogs">
<meta property="twitter:description"
content="Follow the feed and keep up with the tech.">
{% endblock %}

{% block body_css %}background: url('{% static 'img/banner.svg' %}') fixed;{% endblock %}

{% block content %}
<section class="text-white" style="padding: 30px;">
<div class="container">
<div class="row align-items-center">
<div class="col-md">
<h2 class="fw-bold" style="line-height: 40px;">Welcome to the PasteMe Library!</h2>
<p align="justify">In library, our professional writers write awesome articles about tricks, best practices, implementations, and new technologes. Follow the feed and enjoy the blogs.</p>
</div>
<div class="col-md order-first order-md-last" align="center">
<img class="img-fluid" src="{% static 'img/reader_octocat.svg' %}" width="250">
</div>
</div>
</div>
</section>
<section class="p-4 font-dark bg-white">
<div class="container mb-3">
{% if blogs.exists %}
{% for blog in blogs %}
<div class="card card-body" style="border: unset;">
<a href="{% url 'blog' blog.slug %}" class="link-dark" style="text-decoration: unset;"><h3 class="card-title" style="font-family: Lora, serif"><b>{{blog.title}}</b></h3></a>
<p class="card-subtitle mb-2 text-muted">Published on {{blog.published_at | date:'M d, Y'}}</p>
<h5 class="card-text" style="font-family: Lora, serif">{{blog.abstract|truncatechars:85}}</h5>
<p class="card-text mt-1">
{% for tag in blog.tags.all %}
<span class="badge me-1 bg-black">{{tag.name}}</span>
{% endfor %%}
</p>
</div>
{% endfor %}
{% else %}
<h2>No feeds to follow up!</h2>
<p>No blog post found in the archive.</p>
{% endif %}
</div>
</section>
{% endblock %}
12 changes: 12 additions & 0 deletions blog/templatetags/markdown_extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django import template
from django.template.defaultfilters import stringfilter

import markdown as md

register = template.Library()


@register.filter()
@stringfilter
def markdown(value):
return md.markdown(value, extensions=['markdown.extensions.fenced_code'])
3 changes: 3 additions & 0 deletions blog/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions blog/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from .views import api, template


urlpatterns = [
path('', template.BlogListView.as_view(), name='blogs'),
path('<slug:slug>/', template.BlogDetailView.as_view(), name='blog'),
]
Empty file added blog/views/api.py
Empty file.
15 changes: 15 additions & 0 deletions blog/views/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.views.generic import DetailView, ListView

from blog.models import Blog


class BlogListView(ListView):
template_name = 'blogs.html'
queryset = Blog.objects.all().order_by('-published_at')
context_object_name = 'blogs'


class BlogDetailView(DetailView):
model = Blog
template_name = 'blog.html'
context_object_name = 'blog'
1 change: 1 addition & 0 deletions pasteme/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

# apps
'snippet',
'blog',
'pypi',
]

Expand Down
1 change: 1 addition & 0 deletions pasteme/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
urlpatterns = [
# path('admin/', admin.site.urls),
path('apidocs/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('blog/', include('blog.urls')),
path('', include('snippet.urls')),
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ idna==3.3
inflection==0.5.1
itypes==1.2.0
Jinja2==3.1.2
Markdown==3.4.1
MarkupSafe==2.1.1
mbstrdecoder==1.1.0
mysqlclient==2.1.0
Expand Down
32 changes: 32 additions & 0 deletions snippet/static/css/blog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.title, .abstract, .body{
font-family: Lora, serif;
}

.abstract{
text-align: justify;
}

.title{
font-weight: bold;
}

.body h1, h2, h3, h4, h5{
font-weight: bold;
margin-top: 25px;
}

.body p{
font-size: 20px;
text-align: justify;
}

.body a{
color: black;
}

.body code{
color: #fff;
background-color: black;
padding: 0 5px 0px 5px;
border-radius: 3px;blue;
}
1 change: 1 addition & 0 deletions snippet/static/img/reader_octocat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions snippet/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{% block title %}404 - Not Found{% endblock %}

{% block content %}
<section>
<div class="container p-5">
<section class="p-4">
<div class="container">
<div class="container">
<h2>Opps! You're lost.</h2>
<p>Looks the page you're looking for is missing at the moment. I mean 404. :(</p>
Expand Down
14 changes: 6 additions & 8 deletions snippet/templates/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
{% block title %}500 - Some Failures Here{% endblock %}

{% block content %}
<section>
<div class="container p-5">
<div class="container">
<h2>Hmm.. We're facing some issues.</h2>
<p>If the problem still presests, <a href="mailto:lnxpylnxpy@gmail.com">contact me</a> and let me fix the issue. :)</p>
</div>
</div>
</section>
<section class="p-4">
<div class="container">
<h2>Hmm.. We're facing some issues.</h2>
<p>If the problem still presests, <a href="mailto:lnxpylnxpy@gmail.com">contact me</a> and let me fix the issue. :)</p>
</div>
</section>
{% endblock %}
Loading

0 comments on commit d521bce

Please sign in to comment.