This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { markdownToHtml } from '../../shared/lib/markdown.js';
|
||||
|
||||
export function createArticleDraft({ articles, assets }) {
|
||||
return {
|
||||
slug: `new-post-${Date.now()}`,
|
||||
title: 'Новая статья',
|
||||
date: new Date().toISOString(),
|
||||
author: articles[0]?.author || 'DarkRiDDeR',
|
||||
categories: articles[0]?.categories || ['Разное'],
|
||||
cover: assets[0] || '/assets/illustrations/vibe-cover.svg',
|
||||
excerpt: 'Короткий анонс статьи.',
|
||||
contentHtml: markdownToHtml('Текст статьи.'),
|
||||
readingMinutes: 1,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { htmlToMarkdown } from '../../shared/lib/markdown.js';
|
||||
|
||||
export function fillArticleForm(fields, article) {
|
||||
fields.title.value = article.title || '';
|
||||
fields.slug.value = article.slug || '';
|
||||
fields.date.value = article.date || '';
|
||||
fields.author.value = article.author || '';
|
||||
fields.categories.value = (article.categories || []).join(', ');
|
||||
fields.cover.value = article.cover || '';
|
||||
fields.excerpt.value = article.excerpt || '';
|
||||
fields.contentMarkdown.value = article.contentMarkdown || htmlToMarkdown(article.contentHtml || '');
|
||||
fields.readingMinutes.value = article.readingMinutes || 1;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { fillArticleForm } from './fillArticleForm.js';
|
||||
export { readArticleForm } from './readArticleForm.js';
|
||||
@@ -0,0 +1,22 @@
|
||||
import { markdownToHtml } from '../../shared/lib/markdown.js';
|
||||
|
||||
export function readArticleForm(fields, currentArticle) {
|
||||
const article = {
|
||||
...(currentArticle || {}),
|
||||
slug: fields.slug.value.trim(),
|
||||
title: fields.title.value.trim(),
|
||||
date: fields.date.value.trim(),
|
||||
author: fields.author.value.trim(),
|
||||
categories: fields.categories.value
|
||||
.split(',')
|
||||
.map((category) => category.trim())
|
||||
.filter(Boolean),
|
||||
cover: fields.cover.value.trim(),
|
||||
excerpt: fields.excerpt.value.trim(),
|
||||
contentHtml: markdownToHtml(fields.contentMarkdown.value),
|
||||
readingMinutes: Number(fields.readingMinutes.value),
|
||||
};
|
||||
|
||||
delete article.contentMarkdown;
|
||||
return article;
|
||||
}
|
||||
Reference in New Issue
Block a user