fix: publish: auto-include meta description, keywords, image upload, Daniel as author
- Add metadesc + metakey extraction from HTML <meta> tags - Upload article image to Joomla media endpoint before publish - Set created_by=560 (Daniel Krause) for all articles - Image is uploaded as both image_intro and image_fulltext
This commit is contained in:
@@ -1201,7 +1201,50 @@ h1{color:#c0392b;}p{color:#888;}</style></head>
|
|||||||
"state": state,
|
"state": state,
|
||||||
"access": access,
|
"access": access,
|
||||||
"featured": featured,
|
"featured": featured,
|
||||||
|
"created_by": 560, # Daniel Krause
|
||||||
}
|
}
|
||||||
|
# ── Meta-Description & Keywords ─────────────────────────
|
||||||
|
if meta_desc_match and meta_desc_match.group(1).strip():
|
||||||
|
article_payload["metadesc"] = meta_desc_match.group(1).strip()
|
||||||
|
if meta_key_match and meta_key_match.group(1).strip():
|
||||||
|
article_payload["metakey"] = meta_key_match.group(1).strip()
|
||||||
|
# ── Image upload to Joomla ──────────────────────────────
|
||||||
|
if fname in img_map and img_map[fname]:
|
||||||
|
image_path = img_map[fname][0] # First image
|
||||||
|
if os.path.exists(image_path):
|
||||||
|
try:
|
||||||
|
img_filename = os.path.basename(image_path)
|
||||||
|
ext = os.path.splitext(img_filename)[1].lower()
|
||||||
|
mime_map = {".jpg": "image/jpeg", ".jpeg": "image/jpeg",
|
||||||
|
".png": "image/png", ".webp": "image/webp",
|
||||||
|
".gif": "image/gif"}
|
||||||
|
mime_type = mime_map.get(ext, "image/jpeg")
|
||||||
|
with open(image_path, "rb") as img_f:
|
||||||
|
img_resp = requests.post(
|
||||||
|
"https://www.brettspiel-news.de/api/index.php/v1/media",
|
||||||
|
headers={"X-Joomla-Token": JOOMLA_TOKEN},
|
||||||
|
files={"file": (img_filename, img_f, mime_type)},
|
||||||
|
timeout=30
|
||||||
|
)
|
||||||
|
if img_resp.status_code in (200, 201):
|
||||||
|
img_data = img_resp.json()
|
||||||
|
# Joomla 4 returns the relative path
|
||||||
|
j_img_path = None
|
||||||
|
if "data" in img_data and "attributes" in img_data["data"]:
|
||||||
|
j_img_path = img_data["data"]["attributes"].get("path", "")
|
||||||
|
if not j_img_path:
|
||||||
|
j_img_path = f"images/{datetime.now().strftime('%Y/%m')}/{img_filename}"
|
||||||
|
article_payload["images"] = {
|
||||||
|
"image_intro": j_img_path,
|
||||||
|
"image_intro_alt": title,
|
||||||
|
"image_fulltext": j_img_path,
|
||||||
|
"image_fulltext_alt": title,
|
||||||
|
}
|
||||||
|
print(f"[Image] Uploaded {img_filename} → {j_img_path}", flush=True)
|
||||||
|
else:
|
||||||
|
print(f"[Image] Upload failed: HTTP {img_resp.status_code}", flush=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[Image] Upload error: {e}", flush=True)
|
||||||
if featured_up:
|
if featured_up:
|
||||||
article_payload["featured_up"] = featured_up
|
article_payload["featured_up"] = featured_up
|
||||||
if featured_down:
|
if featured_down:
|
||||||
|
|||||||
Reference in New Issue
Block a user