Update metadata and enhance image export functionality: Adjust compatible version and improve image handling in export process.
This commit is contained in:
1 parent
69e50f0927
commit
acc60c7007
2 files changed
+42
-16
No files matched your search
+1
-1
@@ -5,6 +5,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"releaseDate": "2026-06-01",
|
"releaseDate": "2026-06-01",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"compatible": "3.20",
|
"compatible": "3.22.0",
|
||||||
"notes": "Export Bludit articles to a GitHub repository as Markdown files with YAML frontmatter."
|
"notes": "Export Bludit articles to a GitHub repository as Markdown files with YAML frontmatter."
|
||||||
}
|
}
|
||||||
+41
-15
@@ -147,7 +147,12 @@ class pluginBluditGithub extends Plugin
|
|||||||
private function exportPage($page, $saveStatus = true)
|
private function exportPage($page, $saveStatus = true)
|
||||||
{
|
{
|
||||||
$key = $page->getValue('key');
|
$key = $page->getValue('key');
|
||||||
$content = $this->buildMarkdown($page, $key);
|
$rawContent = $page->content();
|
||||||
|
|
||||||
|
// Export images using URLs found in the content (before rewriting)
|
||||||
|
$this->exportImages($key, $rawContent);
|
||||||
|
|
||||||
|
$content = $this->buildMarkdown($page, $key, $rawContent);
|
||||||
$filePath = $this->getFilePath($key);
|
$filePath = $this->getFilePath($key);
|
||||||
$sha = $this->getFileSha($filePath);
|
$sha = $this->getFileSha($filePath);
|
||||||
|
|
||||||
@@ -162,38 +167,59 @@ class pluginBluditGithub extends Plugin
|
|||||||
|
|
||||||
$result = $this->githubRequest('PUT', '/contents/' . $filePath, $data);
|
$result = $this->githubRequest('PUT', '/contents/' . $filePath, $data);
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false && $saveStatus) {
|
||||||
$this->exportImages($key);
|
|
||||||
if ($saveStatus) {
|
|
||||||
$this->setStatus(date('Y-m-d H:i:s') . ' — Exported: ' . $page->title());
|
$this->setStatus(date('Y-m-d H:i:s') . ' — Exported: ' . $page->title());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function exportImages($key)
|
private function exportImages($key, $content)
|
||||||
{
|
{
|
||||||
if (!defined('PATH_UPLOADS_PAGES')) {
|
if (!defined('PATH_UPLOADS_PAGES')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dir = PATH_UPLOADS_PAGES . $key;
|
// Extract every Bludit upload URL from the content.
|
||||||
if (!is_dir($dir)) {
|
// The UUID in the URL is the actual storage directory — it may differ
|
||||||
|
// from the page key's symlink, so we resolve it directly from the URL.
|
||||||
|
preg_match_all(
|
||||||
|
'/https?:\/\/[^\/]+\/bl-content\/uploads\/pages\/([^\/]+)\/([^"\')\s<>]+)/',
|
||||||
|
$content,
|
||||||
|
$matches,
|
||||||
|
PREG_SET_ORDER
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($matches)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$prefix = trim($this->getValue('path'), '/');
|
$prefix = trim($this->getValue('path'), '/');
|
||||||
|
$seen = [];
|
||||||
|
|
||||||
foreach (glob($dir . DS . '*') as $file) {
|
foreach ($matches as $match) {
|
||||||
if (!is_file($file)) {
|
$uuid = $match[1];
|
||||||
|
$filename = $match[2];
|
||||||
|
|
||||||
|
if (isset($seen[$filename])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$filename = basename($file);
|
$seen[$filename] = true;
|
||||||
|
|
||||||
|
// Resolve the file using the UUID path from the URL
|
||||||
|
$localPath = PATH_UPLOADS_PAGES . $uuid . DS . $filename;
|
||||||
|
if (!file_exists($localPath)) {
|
||||||
|
// Fallback: try via the page key symlink
|
||||||
|
$localPath = PATH_UPLOADS_PAGES . $key . DS . $filename;
|
||||||
|
if (!file_exists($localPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$repoPath = ($prefix ? $prefix . '/' : '') . $key . '/' . $filename;
|
$repoPath = ($prefix ? $prefix . '/' : '') . $key . '/' . $filename;
|
||||||
$sha = $this->getFileSha($repoPath);
|
$sha = $this->getFileSha($repoPath);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'message' => ($sha ? 'Update' : 'Add') . ' image: ' . $key . '/' . $filename,
|
'message' => ($sha ? 'Update' : 'Add') . ' image: ' . $key . '/' . $filename,
|
||||||
'content' => base64_encode(file_get_contents($file)),
|
'content' => base64_encode(file_get_contents($localPath)),
|
||||||
'branch' => $this->getValue('branch'),
|
'branch' => $this->getValue('branch'),
|
||||||
];
|
];
|
||||||
if ($sha) {
|
if ($sha) {
|
||||||
@@ -232,14 +258,14 @@ class pluginBluditGithub extends Plugin
|
|||||||
$this->setStatus(date('Y-m-d H:i:s') . " — Bulk export: {$count} articles pushed.");
|
$this->setStatus(date('Y-m-d H:i:s') . " — Bulk export: {$count} articles pushed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildMarkdown($page, $key)
|
private function buildMarkdown($page, $key, $rawContent = null)
|
||||||
{
|
{
|
||||||
$content = $page->content();
|
$content = $rawContent ?? $page->content();
|
||||||
|
|
||||||
// Rewrite absolute Bludit upload URLs to relative filenames
|
// Rewrite absolute Bludit upload URLs to relative filenames
|
||||||
// e.g. https://domain/bl-content/uploads/pages/UUID/image.png → image.png
|
// e.g. https://domain/bl-content/uploads/pages/UUID/image.png → image.png
|
||||||
$content = preg_replace(
|
$content = preg_replace(
|
||||||
'/https?:\/\/[^\/]+\/bl-content\/uploads\/pages\/[^\/]+\/([^"\')\s]+)/',
|
'/https?:\/\/[^\/]+\/bl-content\/uploads\/pages\/[^\/]+\/([^"\')\s<>]+)/',
|
||||||
'$1',
|
'$1',
|
||||||
$content
|
$content
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user