rewrite: Vite+React → Astro 5 + Content Collections
Some checks failed
deploy / deploy (push) Failing after 12s
Some checks failed
deploy / deploy (push) Failing after 12s
- Бэкап старой версии на ветке vite-react-backup - Stack: Astro 5 + nginx:alpine runtime, образ ~50 МБ (был ~600 МБ) - @astrojs/rss заменён ручным buildRss() — гарантия CDATA в content:encoded для IPB Importer - @astrojs/sitemap → sitemap-index.xml + sitemap.txt - 152-ФЗ cookie consent + privacy.astro + Analytics с gating - AI-файлы: robots.txt с явным allow для AI-краулеров, ai.txt, llms.txt - Гибридный визуал: фото-фон шапки (аэрофото Пушкино) + PT Serif + IBM Plex Sans - Иерархия: hero "Главная история" с рамкой + "Ещё из истории" + "Хроника" - Категория "main" (псевдо) скрыта из плашек и из Рубрик в сайдбаре - hideFromList: true для технических постов - featuredImage в frontmatter для постов без хорошей первой <img> - WP resized-URL (-WxH.ext) автоматически → оригинал - CI/CD: .gitea/workflows/deploy.yml (push → SSH-build) - Внешние RSS: scripts/pull-external-rss.mjs пишет news.json в bind-mount, фронт фетчит client-side
This commit is contained in:
90
scripts/convert_to_markdown.py
Normal file
90
scripts/convert_to_markdown.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Convert src/content/{posts,pages}.json → src/content/{posts,pages}/<slug>.md
|
||||
for Astro Content Collections."""
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
CONTENT = ROOT / "src" / "content"
|
||||
POSTS_JSON = CONTENT / "posts.json"
|
||||
PAGES_JSON = CONTENT / "pages.json"
|
||||
POSTS_DIR = CONTENT / "posts"
|
||||
PAGES_DIR = CONTENT / "pages"
|
||||
|
||||
POSTS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
PAGES_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Ручные флаги по slug'у для главной ленты.
|
||||
# featured=True — пинится наверх как hero (отдельная карточка с рамкой).
|
||||
# hideFromList=True — не показывается в общей ленте (виден только в рубрике/архиве).
|
||||
# featuredImage — переопределяет первую <img> из тела для миниатюры/hero.
|
||||
SLUG_FLAGS: dict[str, dict] = {
|
||||
'voronino': {'featured': True, 'featuredImage': '/uploads/IMG_2156.jpg'},
|
||||
'staroe-staroe-selo': {'featured': True, 'featuredImage': '/uploads/IMG_2754.jpg'},
|
||||
'vnimanie-texnicheskie-raboty': {'hideFromList': True},
|
||||
'vnimanie-texnicheskie-raboty-2': {'hideFromList': True},
|
||||
'c-nastupayushhim-novym-2014-godom': {'hideFromList': True},
|
||||
}
|
||||
|
||||
def yaml_escape(s: str) -> str:
|
||||
return s.replace('"', '\\"')
|
||||
|
||||
def make_md(item: dict, kind: str) -> str:
|
||||
fm = [
|
||||
'---',
|
||||
f'title: "{yaml_escape(item["title"])}"',
|
||||
f'slug: {item["slug"]}',
|
||||
f'legacyId: {item["id"]}',
|
||||
]
|
||||
if item.get('date'):
|
||||
date = item['date'].replace(' ', 'T') + '+03:00'
|
||||
if kind == 'post':
|
||||
fm.append(f'pubDate: {date}')
|
||||
else:
|
||||
fm.append(f'pubDate: {date}')
|
||||
if item.get('excerpt'):
|
||||
fm.append(f'description: "{yaml_escape(item["excerpt"])}"')
|
||||
else:
|
||||
fm.append('description: ""')
|
||||
if kind == 'post':
|
||||
if item.get('categories'):
|
||||
fm.append('categories:')
|
||||
for c in item['categories']:
|
||||
fm.append(f' - "{yaml_escape(c)}"')
|
||||
else:
|
||||
fm.append('categories: []')
|
||||
if item.get('categorySlugs'):
|
||||
fm.append('categorySlugs:')
|
||||
for s in item['categorySlugs']:
|
||||
fm.append(f' - "{s}"')
|
||||
else:
|
||||
fm.append('categorySlugs: []')
|
||||
fm.append('author: "История города Пушкино"')
|
||||
if item.get('oldSlug') and item['oldSlug'] != item['slug']:
|
||||
fm.append(f'oldSlug: "{item["oldSlug"]}"')
|
||||
if kind == 'post':
|
||||
flags = SLUG_FLAGS.get(item['slug'], {})
|
||||
if flags.get('featured'):
|
||||
fm.append('featured: true')
|
||||
if flags.get('hideFromList'):
|
||||
fm.append('hideFromList: true')
|
||||
if flags.get('featuredImage'):
|
||||
fm.append(f'featuredImage: "{flags["featuredImage"]}"')
|
||||
fm.append('---')
|
||||
fm.append('')
|
||||
fm.append(item['html'])
|
||||
return '\n'.join(fm) + '\n'
|
||||
|
||||
def convert(json_path: Path, out_dir: Path, kind: str) -> int:
|
||||
items = json.loads(json_path.read_text(encoding='utf-8'))
|
||||
for item in items:
|
||||
md = make_md(item, kind)
|
||||
(out_dir / f'{item["slug"]}.md').write_text(md, encoding='utf-8')
|
||||
return len(items)
|
||||
|
||||
if __name__ == '__main__':
|
||||
n_posts = convert(POSTS_JSON, POSTS_DIR, 'post')
|
||||
n_pages = convert(PAGES_JSON, PAGES_DIR, 'page')
|
||||
print(f'posts: {n_posts} → src/content/posts/')
|
||||
print(f'pages: {n_pages} → src/content/pages/')
|
||||
Reference in New Issue
Block a user