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