Skip to content

Commit

Permalink
new pages
Browse files Browse the repository at this point in the history
  • Loading branch information
potykion committed Jul 15, 2024
1 parent 12b383b commit e992120
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 126 deletions.
26 changes: 23 additions & 3 deletions app_42.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,30 @@ def projects_page():
"n/projects.md",
page=deps.page,
)

@app.route("/n/<page>")
def n_any_page(page):
try:
return render_md_as_html_template(
f"n/{page}.md",
page=deps.page,
)
except FileNotFoundError:
return render_template(
f"n/{page}.html",
page=deps.page,
)

@app.route("/mind/<page>")
def mind_any_page(page):
return render_md_as_html_template(
f"n/{page}.md",
f"mind/{page}.md",
page=deps.page,
)
@app.route("/mind")
def mind_index():
return render_md_as_html_template(
f"mind/index.md",
page=deps.page,
)

Expand All @@ -393,8 +413,8 @@ def n_page():

@app.route("/n/cv")
def n_cv_page():
return render_md_as_html_template(
"n/cv.md",
return render_template(
"n/cv.html",
page=deps.page,
)

Expand Down
Binary file modified potyk-io.db
Binary file not shown.
25 changes: 22 additions & 3 deletions potyk_io_back/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os.path

import flask
from flask import render_template

from potyk_io_back.blog_pages import BlogPageForm, BlogPage
from potyk_io_back.blog_pages import BlogPageForm, BlogPage, BlogPageStore
from potyk_io_back.index_and_feed import (
FeedForm,
FeedCard,
Expand All @@ -11,6 +13,24 @@
)


def create_page(page_form, page_store: BlogPageStore, templates_path: str):
page = BlogPage(**page_form.data)
page_store.insert(page)

page_path = os.path.join(templates_path, page.html_path)
if not os.path.exists(page_path):
os.makedirs(os.path.dirname(page_path), exist_ok=True)
with open(page_path, 'w', encoding='utf-8') as f:
f.write('''{% extends "_layouts/base.html" %}
{% block main %}
TODO
{% endblock %}''')

return page


def add_admin_routes(app: flask.Flask, deps):
@app.route("/admin", methods=["GET", "POST"])
def admin_page():
Expand All @@ -20,8 +40,7 @@ def admin_page():

if flask.request.method == "POST":
if page_form.validate_on_submit():
page = BlogPage(**page_form.data)
deps.page_store.insert(page)
page = create_page(page_form, deps.page_store, flask.current_app.template_folder)
return render_template("_components/htmx_success.html", page=page)
else:
return render_template("_components/htmx_error.html", error=page_form.errors)
Expand Down
38 changes: 30 additions & 8 deletions potyk_io_back/blog_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
import os.path
from enum import auto
from pathlib import Path
from re import Match

import flask
import frontmatter
import markdown
import mistune
from mistune import HTMLRenderer
from mistune import HTMLRenderer, InlineParser, InlineState
from mistune.plugins.footnotes import footnotes
from mistune.plugins.formatting import strikethrough
from mistune.plugins.speedup import speedup
from mistune.plugins.table import table
from mistune.plugins.task_lists import task_lists
from flask import render_template_string, render_template
from flask_wtf import FlaskForm
Expand Down Expand Up @@ -135,8 +141,16 @@ def __init__(self, sqlite_cursor):

def insert(self, page):
self.q.execute(
"insert into blog_pages " "(url, html_path, title, desc, section) " "values " "(?, ?, ?, ?, ?)",
(page.url, page.html_path, page.title, page.desc, page.section),
"insert into blog_pages (url, html_path, title, desc, section, include_in_index, breadcrumbs_title) values (?, ?, ?, ?, ?, ?, ?)",
(
page.url,
page.html_path,
page.title,
page.desc,
page.section,
page.include_in_index,
page.breadcrumbs_title,
),
commit=True,
)

Expand Down Expand Up @@ -201,22 +215,30 @@ class BlogPageForm(FlaskForm):
class TaskListsAndNoEscapeRenderer(HTMLRenderer):
def task_list_item(self, text, checked=False, **attrs):
return render_template("_components/md_checkbox.html", checked=checked, text=text)

def text(self, text: str) -> str:
return text

def paragraph(self, text: str) -> str:
if text.strip().startswith('{%'):
if text.strip().startswith(("{%", "{{")):
return text
else:
return '<p>' + text + '</p>\n'

return "<p>" + text + "</p>\n"


markdown_to_html = mistune.Markdown(TaskListsAndNoEscapeRenderer(escape=False), plugins=[task_lists],)
markdown_to_html = mistune.Markdown(
TaskListsAndNoEscapeRenderer(escape=False),
plugins=[
strikethrough,
footnotes,
table,
task_lists,
],
)


def render_md_as_html_template(template, **kwargs):
template_path = Path(flask.current_app.template_folder).resolve() / template
template_path = BASE_DIR / flask.current_app.template_folder / template

md = frontmatter.load(str(template_path)).content

Expand Down
49 changes: 19 additions & 30 deletions templates/_layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- region SEO -->
<title>{{ title }}</title>
<meta name="description" content="{{ desc }}"/>
<title>{{ page.title }}</title>
<meta name="description" content="{{ page.desc }}"/>

<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ desc }}">
<meta property="og:title" content="{{ page.title }}">
<meta property="og:description" content="{{ page.desc }}">
<!-- endregion SEO -->

<!-- region Styles -->
Expand All @@ -37,7 +37,7 @@

<!-- endregion Styles -->

{% if config.is_prod and page.url != '/login' %}
{% if config.is_prod and page.url != '/login' %}
<script>
if (!localStorage.getItem('tgAuth')) {
window.location.href = '/login';
Expand Down Expand Up @@ -108,27 +108,18 @@
{% if page.breadcrumbs | length > 1 %}
<div class="breadcrumbs uni-border border-b mb-2">
<ul class="!pl-3">
{# <ul >#}
{# <ul class="!pl-0">#}
{% if page %}
<li>
<a class="link-hover " href="/"></a>
</li>
{% for page in page.breadcrumbs[1:] %}
<li>
<a class="link-hover " href="/"></a>

</li>
{% for page in page.breadcrumbs[1:] %}
<li>
{% if loop.last %}
{{ page.breadcrumbs_title }}
{% else %}
<a class="link-hover " href="{{ page.url }}">{{ page.breadcrumbs_title }}</a>
{% endif %}
</li>
{% endfor %}
{% else %}
<li>
<a href="/">потик.ио</a>
{% if loop.last %}
{{ page.breadcrumbs_title }}
{% else %}
<a class="link-hover " href="{{ page.url }}">{{ page.breadcrumbs_title }}</a>
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
Expand All @@ -138,12 +129,10 @@
<main class="prose prose-sm md:prose-base p-2 min-h-[80vh]
{% if fullwidth %}{% else %}max-w-[1000px]{% endif %} mx-auto">
{% block title %}
{% if page %}
<div class="my-2">
<h1>{{ page.title | safe }}</h1>
<cite class="block">{{ (page.desc or '') | safe }}</cite>
</div>
{% endif %}
<div class="my-2">
<h1>{{ page.title | safe }}</h1>
<cite class="block">{{ (page.desc or '') | safe }}</cite>
</div>
{% endblock %}

{% block main %}{% endblock %}
Expand Down
26 changes: 12 additions & 14 deletions templates/_layouts/blank.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- region SEO -->
<title>{{ title }}</title>
<meta name="description" content="{{ desc }}"/>

<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ desc }}">
<title>{{ page.title }}</title>
<meta name="description" content="{{ page.desc }}"/>

<meta property="og:title" content="{{ page.title }}">
<meta property="og:url" content="{{ page.url }}">
<meta property="og:description" content="{{ page.desc }}">

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:site" content="potyk.io"/>
<meta name="twitter:title" content="{{ page.title }}"/>
<meta name="twitter:description" content="{{ page.desc }}"/>
<meta name="twitter:image" content=""/>
<!-- endregion SEO -->

<!-- region Styles -->
Expand Down Expand Up @@ -87,20 +94,11 @@

<main class="prose prose-sm md:prose-base p-2 min-h-[80vh]
{% if fullwidth %}{% else %}max-w-[1000px]{% endif %} mx-auto">
{% block title %}
{% if page %}
<div class="my-2">
<h1>{{ page.title | safe }}</h1>
<cite class="block">{{ (page.desc or '') | safe }}</cite>
</div>
{% endif %}
{% endblock %}

{% block main %}{% endblock %}
</main>



</body>

{% block script %}
Expand Down
7 changes: 7 additions & 0 deletions templates/n/body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Размер одежды: XL

## Размер Обуви

| UK | EUR | US | CM |
|----|-----|----|----|
| 11 | 46 | 12 | 30 |
61 changes: 61 additions & 0 deletions templates/n/cv.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends "_layouts/blank.html" %}

{% block main %}

<div class="my-2 flex justify-between">
<div>
<h1>Лейбович Никита</h1>
<div class="flex gap-2 my-4">
<a class="btn btn-sm btn-primary" href="mailto:[email protected]">Почта</a>
<a class="btn btn-sm btn-primary" href="https://t.me/potykion">Telegram</a>
<a class="btn btn-sm btn-primary" href="https://github.com/potykion">Github</a>
</div>

<h2>Python Backend Developer</h2>
<ul>
<li><strong>Желаемая зарплата:</strong> 400 000 ₽</li>
<li><strong>Навыки:</strong> Django • Flask • pytest • mypy • Google Cloud • BitBucket Pipelines</li>
<li><strong>Open Source:</strong>
<a href="https://github.com/pydantic/pydantic/pull/444">pydantic#444</a>
<a href="https://github.com/yc-actions/yc-sls-container-deploy/pull/427">yc-sls-container-deploy#427</a>
<a href="https://github.com/python/typeshed/pull/2278">typeshed#2278</a>
</li>
<li>
<strong>Мои проекты:</strong>
<a href="https://potyk.io/">potyk.io</a>
<a href="https://github.com/potykion/jinja2xlsx">jinja2xlsx</a>
<a href="https://github.com/potykion/repka">repka</a></li>
</ul>
</div>

<div>
<img src="/static/images/me.jpeg" class="w-32 ">
</div>
</div>

<h2>Опыт работы</h2>
<h3><a href="https://rbcn.mobi/">RuBeacon</a> • 2016 — 2024</h3>
<ul>
<li>Сервер для мобильных приложений по доставке еды <strong>[Google App Engine, webapp2, Flask]</strong></li>
<li>Перевод 100000 строк кода с Python 2 на Python 3 <strong>[six, mypy, Flask]</strong></li>
<li>CI для проверки качества кода и деплоя <strong>[Bitbucket Pipelines, pytest, mypy, ruff]</strong></li>
<li>Оптимизация трат в облаке <strong>[Google Cloud Monitoring, Google Cloud Logging, BigQuery]</strong></li>
<li>Система электронного документооборота <strong>[Django, pydantic, openpyxl, pdfKit, docxtpl]</strong></li>
<li>Интеграции с системами доставки: Iiko, FrontPad, Mobidel <strong>[requests, xmltodict, lxml]</strong></li>
<li>Telegram бот для уведомлений о заказах <strong>[python-telegram-bot]</strong></li>
<li>Система синхронизации данных из Google DataStore в BigQuery <strong>[Google ndb, BigQuery]</strong></li>
</ul>
<h3><a href="https://web-aspect.ru/">WebAspect</a> • 2021 — 2023</h3>
<ul>
<li>Интеграции с медицинскими системами ЕРИС ЕМИАС <strong>[requests, lxml]</strong></li>
<li>Поддержка нескольких бд, оптимизация и кеширование запросов <strong>[Django, Redis, pandas]</strong></li>
<li>Межсерверное взаимодействие между медицинскими организациями <strong>[Django, requests]</strong></li>
</ul>
<h3><a href="https://mcdonalds.ru/">McDonald's</a> • 2017 — 2019</h3>
<ul>
<li>Админка и API для мобильного приложения McDonald's <strong>[Django, Gentelella]</strong></li>
<li>API для акции "Монополия" <strong>[Django Rest Framework, Celery, requests]</strong></li>
<li>Плагин для кассы для сканирования QR-кодов <strong>[wxPython, PyInstaller]</strong></li>
</ul>
{% endblock %}
Loading

0 comments on commit e992120

Please sign in to comment.