-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from collove/feature/blog
Blog Section Added fixes #55
- Loading branch information
Showing
26 changed files
with
347 additions
and
16 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
], | ||
), | ||
] |
29 changes: 29 additions & 0 deletions
29
blog/migrations/0002_blog_absract_alter_blog_published_at_alter_blog_slug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}} · | ||
{% 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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
|
||
# apps | ||
'snippet', | ||
'blog', | ||
'pypi', | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.