Прямой конвертер в Markdown
This commit is contained in:
parent
c8dede39e6
commit
56da7fc57e
|
@ -2,6 +2,8 @@
|
|||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"directus/sdk": "dev-d64",
|
||||
"voku/simple-mysqli": "^3.0"
|
||||
"voku/simple-mysqli": "^3.0",
|
||||
"symfony/yaml": "^5.0@dev",
|
||||
"cocur/slugify": "dev-master"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,73 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "2f6fc5858111a5fe4c1bb1d335b5b370",
|
||||
"content-hash": "69a88b4ef4f4c716a02236ce76c5bdd6",
|
||||
"packages": [
|
||||
{
|
||||
"name": "cocur/slugify",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cocur/slugify.git",
|
||||
"reference": "d41701efe58ba2df9cae029c3d21e1518cc6780e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cocur/slugify/zipball/d41701efe58ba2df9cae029c3d21e1518cc6780e",
|
||||
"reference": "d41701efe58ba2df9cae029c3d21e1518cc6780e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/framework": "~5.1",
|
||||
"latte/latte": "~2.2",
|
||||
"league/container": "^2.2.0",
|
||||
"mikey179/vfsstream": "~1.6",
|
||||
"mockery/mockery": "~0.9",
|
||||
"nette/di": "~2.2",
|
||||
"phpunit/phpunit": "~4.8.36|~5.2",
|
||||
"pimple/pimple": "~1.1",
|
||||
"plumphp/plum": "~0.1",
|
||||
"silex/silex": "~1.3",
|
||||
"symfony/config": "~2.4|~3.0|~4.0",
|
||||
"symfony/dependency-injection": "~2.4|~3.0|~4.0",
|
||||
"symfony/http-kernel": "~2.4|~3.0|~4.0",
|
||||
"twig/twig": "~1.26|~2.0",
|
||||
"zendframework/zend-modulemanager": "~2.2",
|
||||
"zendframework/zend-servicemanager": "~2.2",
|
||||
"zendframework/zend-view": "~2.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Cocur\\Slugify\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ivo Bathke",
|
||||
"email": "ivo.bathke@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Florian Eckerstorfer",
|
||||
"email": "florian@eckerstorfer.co",
|
||||
"homepage": "https://florian.ec"
|
||||
}
|
||||
],
|
||||
"description": "Converts a string into a slug.",
|
||||
"keywords": [
|
||||
"slug",
|
||||
"slugify"
|
||||
],
|
||||
"time": "2019-01-31T20:38:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "directus/collection",
|
||||
"version": "dev-d64",
|
||||
|
@ -855,6 +920,65 @@
|
|||
],
|
||||
"time": "2019-05-28T14:14:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/yaml.git",
|
||||
"reference": "e464640dd39fb6cf1ffb29ba11d31f8d3e41faa4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/yaml/zipball/e464640dd39fb6cf1ffb29ba11d31f8d3e41faa4",
|
||||
"reference": "e464640dd39fb6cf1ffb29ba11d31f8d3e41faa4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.9",
|
||||
"symfony/polyfill-ctype": "~1.8"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/console": "<4.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/console": "^4.4|^5.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/console": "For validating YAML files using the lint command"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Yaml\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony Yaml Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2019-05-31T10:46:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "voku/arrayy",
|
||||
"version": "2.2.9",
|
||||
|
@ -1200,7 +1324,9 @@
|
|||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"directus/sdk": 20
|
||||
"directus/sdk": 20,
|
||||
"symfony/yaml": 20,
|
||||
"cocur/slugify": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
|
|
|
@ -25,7 +25,7 @@ function import_posts($db, $client)
|
|||
{
|
||||
echo $post['name'].PHP_EOL;
|
||||
try {
|
||||
$client->createEntry('posts', [
|
||||
$client->createEntry('oreolek_blog', [
|
||||
'title' => $post['name'],
|
||||
'active' => get_active($post['is_draft']),
|
||||
'published_at' => $post['posted_at'],
|
||||
|
@ -53,14 +53,14 @@ function import_tags($db, $client)
|
|||
$tag = $tags[$row['tag_id']];
|
||||
echo $tag.PHP_EOL;
|
||||
try {
|
||||
$post_tags = $client->getEntry('posts', $row['post_id'])->tags;
|
||||
$post_tags = $client->getEntry('oreolek_blog', $row['post_id'])->tags;
|
||||
if (!empty($post_tags))
|
||||
{
|
||||
$post_tags = $post_tags . ", " . $tag;
|
||||
} else {
|
||||
$post_tags = $tag;
|
||||
}
|
||||
$client->updateEntry('posts', $row['post_id'], [
|
||||
$client->updateEntry('oreolek_blog', $row['post_id'], [
|
||||
'tags' => $post_tags,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
|
@ -76,7 +76,7 @@ function import_pages($db, $client)
|
|||
{
|
||||
echo $page['name'].PHP_EOL;
|
||||
try {
|
||||
$client->createEntry('pages', [
|
||||
$client->createEntry('oreolek_blog_pages', [
|
||||
'title' => $page['name'],
|
||||
'active' => get_active($page['is_draft']),
|
||||
'ID' => $page['id'],
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
use voku\db\DB;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Cocur\Slugify\Slugify;
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
@mkdir('markdown');
|
||||
@mkdir('markdown/posts');
|
||||
$db = DB::getInstance('localhost', 'root', '123456', 'oreolek');
|
||||
$slugify = new Slugify();
|
||||
|
||||
function get_active($draft)
|
||||
{
|
||||
if ($draft == '1')
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
function import_posts($db)
|
||||
{
|
||||
global $slugify;
|
||||
$result = $db->query("SELECT * FROM tags")->fetchAllArray();
|
||||
$tags = [];
|
||||
foreach($result as $row)
|
||||
{
|
||||
$tags[$row['id']] = $row['name'];
|
||||
}
|
||||
$posts = $db->query("SELECT * FROM posts")->fetchAllArray();
|
||||
foreach($posts as $post)
|
||||
{
|
||||
$tagarray = [];
|
||||
$id = $post['id'];
|
||||
$result = $db->query("SELECT * FROM posts_tags WHERE post_id = $id")->fetchAllArray();
|
||||
foreach($result as $row)
|
||||
{
|
||||
$tagarray[] = $tags[$row['tag_id']];
|
||||
}
|
||||
echo $post['name'].PHP_EOL;
|
||||
$metadata = [
|
||||
'title' => $post['name'],
|
||||
'active' => get_active($post['is_draft']),
|
||||
'published_at' => $post['posted_at'],
|
||||
'password' => $post['password'],
|
||||
'tags' => $tagarray
|
||||
];
|
||||
$slug = $slugify->slugify($post['name']);
|
||||
$content = '---'.PHP_EOL.Yaml::dump($metadata).'---'
|
||||
.PHP_EOL.$post['content'];
|
||||
$date = new \DateTime($post['posted_at']);
|
||||
$filename = './markdown/posts/'.$date->format('Y-m-d').'-'.$slug.'.md';
|
||||
$postarray[$post['id']] = $filename;
|
||||
file_put_contents($filename, $content);
|
||||
echo $filename.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function import_pages($db)
|
||||
{
|
||||
global $slugify;
|
||||
$pages = $db->query("SELECT * FROM pages")->fetchAllArray();
|
||||
foreach($pages as $page)
|
||||
{
|
||||
echo $page['name'].PHP_EOL;
|
||||
$metadata = [
|
||||
'title' => $page['name'],
|
||||
'active' => get_active($page['is_draft']),
|
||||
];
|
||||
$slug = $slugify->slugify($page['name']);
|
||||
$filename = './markdown/'.$slug.'.md';
|
||||
$content = '---'.PHP_EOL.Yaml::dump($metadata).'---'
|
||||
.PHP_EOL.$page['content'];
|
||||
file_put_contents($filename, $content);
|
||||
}
|
||||
}
|
||||
|
||||
import_posts($db);
|
||||
import_pages($db);
|
|
@ -18,7 +18,7 @@ const client = new directus({
|
|||
apiVersion: 1 // Optional - default 1
|
||||
});
|
||||
|
||||
client.getItems('posts')
|
||||
client.getItems('oreolek_blog')
|
||||
.catch(error => console.error(error))
|
||||
.then(res => {
|
||||
if (res === undefined) {
|
||||
|
@ -61,7 +61,7 @@ client.getItems('posts')
|
|||
};
|
||||
});
|
||||
|
||||
client.getItems('pages')
|
||||
client.getItems('oreolek_blog_pages')
|
||||
.catch(error => console.error(error))
|
||||
.then(res => {
|
||||
if (res === undefined) {
|
||||
|
|
Loading…
Reference in New Issue