description for new pages
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
.env
|
||||
output/*.md
|
||||
output/*.txt
|
||||
28
generator.py
28
generator.py
@@ -30,6 +30,7 @@ import urllib.error
|
||||
|
||||
OUTPUT_DIR = "output"
|
||||
SOURCE_FILE = os.path.join(OUTPUT_DIR, "SOURCE.md")
|
||||
SOURCE_TITLE_FILE = os.path.join(OUTPUT_DIR, "SOURCE_TITLE.txt")
|
||||
BLOGPOST_FILE = os.path.join(OUTPUT_DIR, "BLOGPOST.md")
|
||||
TRANSLATED_FILE = os.path.join(OUTPUT_DIR, "TRANSLATED_BLOGPOST.md")
|
||||
INSTRUCTIONS_FILE = "INSTRUCTIONS.md"
|
||||
@@ -83,9 +84,9 @@ query ($path: String!) {
|
||||
"""
|
||||
|
||||
MUTATION_UPDATE_PAGE = """
|
||||
mutation ($id: Int!, $content: String!) {
|
||||
mutation ($id: Int!, $content: String!, $description: String!) {
|
||||
pages {
|
||||
update(id: $id, content: $content, tags: ["blog"]) {
|
||||
update(id: $id, content: $content, description: $description, tags: ["blog"]) {
|
||||
responseResult { succeeded message }
|
||||
}
|
||||
}
|
||||
@@ -93,7 +94,7 @@ mutation ($id: Int!, $content: String!) {
|
||||
"""
|
||||
|
||||
MUTATION_CREATE_PAGE = """
|
||||
mutation ($path: String!, $title: String!, $content: String!) {
|
||||
mutation ($path: String!, $title: String!, $content: String!, $description: String!) {
|
||||
pages {
|
||||
create(
|
||||
path: $path
|
||||
@@ -104,7 +105,7 @@ mutation ($path: String!, $title: String!, $content: String!) {
|
||||
isPublished: true
|
||||
isPrivate: false
|
||||
tags: ["blog"]
|
||||
description: ""
|
||||
description: $description
|
||||
) {
|
||||
responseResult { succeeded message }
|
||||
page { id }
|
||||
@@ -191,13 +192,13 @@ class WikiJS:
|
||||
page = resp.get("data", {}).get("pages", {}).get("singleByPath")
|
||||
return page.get("id") if page else None
|
||||
|
||||
def update_page(self, page_id: int, content: str):
|
||||
variables = {"id": page_id, "content": content}
|
||||
def update_page(self, page_id: int, content: str, description: str):
|
||||
variables = {"id": page_id, "content": content, "description": description}
|
||||
resp = self.graphql(MUTATION_UPDATE_PAGE, variables)
|
||||
return resp.get("data", {}).get("pages", {}).get("update", {}).get("responseResult", {}), resp
|
||||
|
||||
def create_page(self, path: str, title: str, content: str):
|
||||
variables = {"path": path, "title": title, "content": content}
|
||||
def create_page(self, path: str, title: str, content: str, description: str):
|
||||
variables = {"path": path, "title": title, "content": content, "description": description}
|
||||
resp = self.graphql(MUTATION_CREATE_PAGE, variables)
|
||||
return resp.get("data", {}).get("pages", {}).get("create", {}).get("responseResult", {}), resp
|
||||
|
||||
@@ -242,6 +243,7 @@ class BlogWriter:
|
||||
sys.exit(1)
|
||||
|
||||
write_file(SOURCE_FILE, page["content"])
|
||||
write_file(SOURCE_TITLE_FILE, page["title"])
|
||||
|
||||
def write(self):
|
||||
original_lang = require_env("ORIGINAL_LANG", "Hungarian")
|
||||
@@ -275,6 +277,7 @@ class BlogWriter:
|
||||
|
||||
def upload(self):
|
||||
content = read_file(TRANSLATED_FILE)
|
||||
description = read_file(SOURCE_TITLE_FILE).strip()
|
||||
|
||||
# Extract H1 title
|
||||
match = re.search(r"^#\s+(.+)", content, re.MULTILINE)
|
||||
@@ -288,17 +291,18 @@ class BlogWriter:
|
||||
page_path = f"blog/{kebab}"
|
||||
|
||||
print(f"→ Uploading to Wiki.js")
|
||||
print(f" Title : {title}")
|
||||
print(f" Path : /{page_path}")
|
||||
print(f" Title : {title}")
|
||||
print(f" Path : /{page_path}")
|
||||
print(f" Description: {description}")
|
||||
|
||||
existing_id = self.wiki.find_page_id(page_path)
|
||||
|
||||
if existing_id:
|
||||
print(f" Found existing page id={existing_id}, updating...")
|
||||
result, resp = self.wiki.update_page(existing_id, content)
|
||||
result, resp = self.wiki.update_page(existing_id, content, description)
|
||||
else:
|
||||
print(" Page not found, creating new...")
|
||||
result, resp = self.wiki.create_page(page_path, title, content)
|
||||
result, resp = self.wiki.create_page(page_path, title, content, description)
|
||||
|
||||
errors = resp.get("errors")
|
||||
if errors:
|
||||
|
||||
Reference in New Issue
Block a user