diff --git a/blog/__init__.py b/blog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/admin.py b/blog/admin.py new file mode 100644 index 0000000..7b2a49b --- /dev/null +++ b/blog/admin.py @@ -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) \ No newline at end of file diff --git a/blog/apps.py b/blog/apps.py new file mode 100644 index 0000000..94788a5 --- /dev/null +++ b/blog/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class BlogConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'blog' diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py new file mode 100644 index 0000000..cfa6890 --- /dev/null +++ b/blog/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/blog/migrations/0002_blog_absract_alter_blog_published_at_alter_blog_slug.py b/blog/migrations/0002_blog_absract_alter_blog_published_at_alter_blog_slug.py new file mode 100644 index 0000000..ac12427 --- /dev/null +++ b/blog/migrations/0002_blog_absract_alter_blog_published_at_alter_blog_slug.py @@ -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), + ), + ] diff --git a/blog/migrations/0003_rename_absract_blog_abstract.py b/blog/migrations/0003_rename_absract_blog_abstract.py new file mode 100644 index 0000000..a420462 --- /dev/null +++ b/blog/migrations/0003_rename_absract_blog_abstract.py @@ -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', + ), + ] diff --git a/blog/migrations/0004_tag_blog_tags.py b/blog/migrations/0004_tag_blog_tags.py new file mode 100644 index 0000000..c6aee7f --- /dev/null +++ b/blog/migrations/0004_tag_blog_tags.py @@ -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'), + ), + ] diff --git a/blog/migrations/__init__.py b/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/models.py b/blog/models.py new file mode 100644 index 0000000..35a5bcd --- /dev/null +++ b/blog/models.py @@ -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) \ No newline at end of file diff --git a/blog/templates/blog.html b/blog/templates/blog.html new file mode 100644 index 0000000..db41efc --- /dev/null +++ b/blog/templates/blog.html @@ -0,0 +1,49 @@ +{% extends '_base.html' %} +{% load static %} +{% load markdown_extras %} + +{% block title %}{{blog.title}}{% endblock %} + +{% block metas %} + + + + + + + + + + + + + +{% endblock %} + +{% block addon_link %} + +{% endblock %} + +{% block blog_active %}active{% endblock %} + +{% block content %} +
+
+
+

{{blog.title}}

+

Published on {{blog.published_at | date:'M d, Y'}} · + {% for tag in blog.tags.all %} + {{tag.name}} + {% endfor %%} +

+
{{blog.abstract}}
+
{{blog.body | markdown | safe}}
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/blog/templates/blogs.html b/blog/templates/blogs.html new file mode 100644 index 0000000..043d41d --- /dev/null +++ b/blog/templates/blogs.html @@ -0,0 +1,66 @@ +{% extends '_base.html' %} +{% load static %} + +{% block title %}PasteMe - Blogs{% endblock %} + +{% block blog_active %}active{% endblock %} + +{% block metas %} + + + + + + + + + + + + + +{% endblock %} + +{% block body_css %}background: url('{% static 'img/banner.svg' %}') fixed;{% endblock %} + +{% block content %} +
+
+
+
+

Welcome to the PasteMe Library!

+

In library, our professional writers write awesome articles about tricks, best practices, implementations, and new technologes. Follow the feed and enjoy the blogs.

+
+
+ +
+
+
+
+
+
+ {% if blogs.exists %} + {% for blog in blogs %} +
+

{{blog.title}}

+

Published on {{blog.published_at | date:'M d, Y'}}

+
{{blog.abstract|truncatechars:85}}
+

+ {% for tag in blog.tags.all %} + {{tag.name}} + {% endfor %%} +

+
+ {% endfor %} + {% else %} +

No feeds to follow up!

+

No blog post found in the archive.

+ {% endif %} +
+
+{% endblock %} \ No newline at end of file diff --git a/blog/templatetags/markdown_extras.py b/blog/templatetags/markdown_extras.py new file mode 100644 index 0000000..d303dcc --- /dev/null +++ b/blog/templatetags/markdown_extras.py @@ -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']) \ No newline at end of file diff --git a/blog/tests.py b/blog/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/blog/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/blog/urls.py b/blog/urls.py new file mode 100644 index 0000000..02792c7 --- /dev/null +++ b/blog/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from .views import api, template + + +urlpatterns = [ + path('', template.BlogListView.as_view(), name='blogs'), + path('/', template.BlogDetailView.as_view(), name='blog'), +] \ No newline at end of file diff --git a/blog/views/api.py b/blog/views/api.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/views/template.py b/blog/views/template.py new file mode 100644 index 0000000..63b7cbd --- /dev/null +++ b/blog/views/template.py @@ -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' \ No newline at end of file diff --git a/pasteme/settings.py b/pasteme/settings.py index b688b86..b800c83 100644 --- a/pasteme/settings.py +++ b/pasteme/settings.py @@ -45,6 +45,7 @@ # apps 'snippet', + 'blog', 'pypi', ] diff --git a/pasteme/urls.py b/pasteme/urls.py index e5fa3a8..e22a7c6 100644 --- a/pasteme/urls.py +++ b/pasteme/urls.py @@ -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')), ] diff --git a/requirements.txt b/requirements.txt index 6253f4e..3fca26a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/snippet/static/css/blog.css b/snippet/static/css/blog.css new file mode 100644 index 0000000..6f768e9 --- /dev/null +++ b/snippet/static/css/blog.css @@ -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; +} \ No newline at end of file diff --git a/snippet/static/img/reader_octocat.svg b/snippet/static/img/reader_octocat.svg new file mode 100755 index 0000000..fefaa9b --- /dev/null +++ b/snippet/static/img/reader_octocat.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/snippet/templates/404.html b/snippet/templates/404.html index b1e7727..6da8a30 100644 --- a/snippet/templates/404.html +++ b/snippet/templates/404.html @@ -2,8 +2,8 @@ {% block title %}404 - Not Found{% endblock %} {% block content %} -
-
+
+

Opps! You're lost.

Looks the page you're looking for is missing at the moment. I mean 404. :(

diff --git a/snippet/templates/500.html b/snippet/templates/500.html index 2e2d0ef..97888f9 100644 --- a/snippet/templates/500.html +++ b/snippet/templates/500.html @@ -2,12 +2,10 @@ {% block title %}500 - Some Failures Here{% endblock %} {% block content %} -
-
-
-

Hmm.. We're facing some issues.

-

If the problem still presests, contact me and let me fix the issue. :)

-
-
-
+
+
+

Hmm.. We're facing some issues.

+

If the problem still presests, contact me and let me fix the issue. :)

+
+
{% endblock %} diff --git a/snippet/templates/home.html b/snippet/templates/home.html index 0b0229b..51d1fab 100644 --- a/snippet/templates/home.html +++ b/snippet/templates/home.html @@ -1,7 +1,7 @@ {% extends '_base.html' %} {% load static %} -{% block addon_style %} +{% block addon_link %} {% endblock %} diff --git a/snippet/templates/snippet.html b/snippet/templates/snippet.html index 6fb090b..8c7adb7 100644 --- a/snippet/templates/snippet.html +++ b/snippet/templates/snippet.html @@ -21,7 +21,7 @@ {% endblock %} -{% block addon_style %} +{% block addon_link %} {% endblock %} @@ -35,8 +35,8 @@ {% endblock %} {% block content %} -
-
+
+

{{snippet.title}}

{{snippet.get_language_display}} {{snippet.get_theme_display}} Theme - {{snippet.created_at.date}}

diff --git a/templates/_base.html b/templates/_base.html index 67ecdcb..e110ae8 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -27,12 +27,13 @@ {% endblock %} {% block title %} - PasteMe Service + PasteMe - Paste Codes From Your Terminal {% endblock title %} + - {% block addon_style %}{% endblock %} + {% block addon_link %}{% endblock %}