Skip to content

Pages

The Konigle SDK provides comprehensive page management for creating and managing website pages. Pages support rich content, SEO metadata, author attribution, and various page types for different use cases.

Creating Pages

Basic Page Creation

import konigle
from konigle.models.website import PageCreate, PageType

client = konigle.Client(api_key="your-api-key")

# Create a simple page
page_data = PageCreate(
    name="About Us",
    title="About Our Company",
    handle="about-us",
    page_type=PageType.ABOUT,
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "type": "paragraph",
                "data": {
                    "text": "Welcome to our company. We are dedicated to providing excellent service."
                }
            }
        ],
        "version": "2.28.0"
    }
)

page = client.pages.create(page_data)
print(f"Created page: {page.id}")
print(f"Page URL: /{page.handle}")
print(f"Published: {page.published}")

Page with Auto-generated Handle

# Handle will be auto-generated from title if not provided
page_data = PageCreate(
    name="Contact Information",
    title="Get In Touch With Us",
    page_type=PageType.CONTACT,
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "type": "paragraph",
                "data": {"text": "Contact us for any inquiries or support."}
            }
        ],
        "version": "2.28.0"
    }
)

page = client.pages.create(page_data)
print(f"Auto-generated handle: {page.handle}")  # "get-in-touch-with-us"

Page with Rich Content (EditorJS Format)

# Create page with rich EditorJS content
page_data = PageCreate(
    name="Privacy Policy",
    title="Privacy Policy",
    handle="privacy",
    page_type=PageType.PRIVACY,
    subtitle="How we protect your data",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "type": "header",
                "data": {
                    "text": "Data Collection",
                    "level": 2
                }
            },
            {
                "type": "paragraph",
                "data": {
                    "text": "We collect information to provide better services to our users."
                }
            },
            {
                "type": "list",
                "data": {
                    "style": "unordered",
                    "items": [
                        "Personal information you provide",
                        "Usage data and analytics",
                        "Device and browser information"
                    ]
                }
            },
            {
                "type": "header",
                "data": {
                    "text": "Data Usage",
                    "level": 2
                }
            },
            {
                "type": "paragraph",
                "data": {
                    "text": "Your data is used to improve our services and provide personalized experiences."
                }
            }
        ],
        "version": "2.28.0"
    }
)

page = client.pages.create(page_data)
print(f"Rich content page created: {page.title}")

Page with SEO Metadata

from konigle.models import SEOMeta

# Create page with complete SEO optimization
page_data = PageCreate(
    name="Terms of Service",
    title="Terms of Service",
    handle="terms",
    page_type=PageType.TERMS,
    subtitle="Important legal information",
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "type": "paragraph",
                "data": {"text": "These terms govern your use of our service."}
            }
        ],
        "version": "2.28.0"
    },
    seo_meta=SEOMeta(
        title="Terms of Service | Your Company",
        description="Read our terms of service and understand your rights and responsibilities",
        keywords="terms,service,legal,policy,agreement",
        og_title="Terms of Service",
        og_description="Important legal terms for using our service",
        og_image="https://example.com/terms-banner.jpg",
        twitter_title="Terms of Service",
        twitter_description="Legal terms for our service"
    ),
    json_ld={
        "@context": "https://schema.org",
        "@type": "WebPage",
        "name": "Terms of Service",
        "description": "Legal terms and conditions"
    },
    exclude_from_sitemap=False,
    show_author=False
)

page = client.pages.create(page_data)
print(f"SEO-optimized page created: {page.title}")

Page with Author Attribution

# Create page with author and contributors
page_data = PageCreate(
    name="Company History",
    title="Our Journey and Milestones",
    handle="history",
    page_type=PageType.ABOUT,
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "type": "paragraph",
                "data": {"text": "Founded in 2020, our company has grown steadily..."}
            }
        ],
        "version": "2.28.0"
    },
    author="author_123456789",
    contributor_ids=["author_111", "author_222"],
    reviewer_ids=["author_333"],
    show_author=True
)

page = client.pages.create(page_data)
print(f"Page with author attribution created: {page.title}")

Different Page Types

# About page
about_page = client.pages.create(PageCreate(
    name="About",
    title="About Our Company",
    page_type=PageType.ABOUT,
    content={"blocks": [{"type": "paragraph", "data": {"text": "About us content"}}]}
))

# FAQ page
faq_page = client.pages.create(PageCreate(
    name="FAQ",
    title="Frequently Asked Questions",
    page_type=PageType.FAQ,
    content={"blocks": [{"type": "paragraph", "data": {"text": "FAQ content"}}]}
))

# Contact page
contact_page = client.pages.create(PageCreate(
    name="Contact",
    title="Contact Us",
    page_type=PageType.CONTACT,
    content={"blocks": [{"type": "paragraph", "data": {"text": "Contact information"}}]}
))

# General page
general_page = client.pages.create(PageCreate(
    name="Services",
    title="Our Services",
    page_type=PageType.GENERAL,
    content={"blocks": [{"type": "paragraph", "data": {"text": "Services overview"}}]}
))

Listing Pages

Basic Page Listing

# List all pages with pagination
pages = client.pages.list(page=1, page_size=20)

print(f"Total pages: {pages.count}")
print(f"Current page: {pages.current_page}")
print(f"Total pages: {pages.num_pages}")

for page in pages.payload:
    print(f"- {page.title} ({page.page_type})")
    print(f"  Handle: {page.handle}")
    print(f"  Published: {page.published}")

Filtering Pages

from konigle.filters.website import PageFilters

# Using filter object (type-safe)
page_filters = PageFilters(
    q="about",  # Search in title and name
    page_type="about",
    folder="folder_123",  # Filter by folder
    published=True,
    ordering="title"  # Sort by title
)

filtered_pages = client.pages.list(
    page=1,
    page_size=10,
    filters=page_filters
)

# Using filter kwargs (more concise)
about_pages = client.pages.list(
    page_type="about",
    q="company",
    ordering="-created_at"  # Sort by newest first
)

# Filter by publication status
published_pages = client.pages.list(published=True)
draft_pages = client.pages.list(published=False)

# Search pages by content
search_results = client.pages.list(q="privacy policy")

Getting a Specific Page

# Get page by ID
page = client.pages.get("page_123456789")
print(f"Page: {page.title}")
print(f"Type: {page.page_type}")
print(f"Handle: {page.handle}")
print(f"Author: {page.author}")
print(f"Contributors: {len(page.contributors)}")
print(f"Content blocks: {len(page.content.get('blocks', []))}")

Updating Pages

from konigle.models.website import PageUpdate

# Update page metadata
update_data = PageUpdate(
    title="Updated About Us",
    subtitle="Learn more about our updated mission",
    seo_meta=SEOMeta(
        title="Updated About Us | Company",
        description="Updated information about our company"
    )
)

updated_page = client.pages.update("page_123456789", update_data)
print(f"Updated page: {updated_page.title}")

# Update page content
content_update = PageUpdate(
    content={
        "time": 1672531200000,
        "blocks": [
            {
                "type": "header",
                "data": {"text": "Updated Content", "level": 1}
            },
            {
                "type": "paragraph",
                "data": {"text": "This is the updated page content with new information."}
            }
        ],
        "version": "2.28.0"
    }
)

page_with_new_content = client.pages.update("page_123456789", content_update)

Deleting Pages

# Delete a page
success = client.pages.delete("page_123456789")
if success:
    print("Page deleted successfully")
else:
    print("Failed to delete page")

Page Actions

Publishing and Unpublishing Pages

# Publish a page to make it live on your website
page = client.pages.get("page_123456789")
published_page = page.publish()
print(f"Page published: {published_page.published}")
print(f"Published at: {published_page.published_at}")

# Or use the manager directly
published_page = client.pages.publish("page_123456789")

# Unpublish a page to take it offline
unpublished_page = page.unpublish()
print(f"Page unpublished: {unpublished_page.published}")

# Or use the manager directly
unpublished_page = client.pages.unpublish("page_123456789")

Changing Page Handles

# Change a page's URL handle
page = client.pages.get("page_123456789")

# Change handle without redirect
updated_page = page.change_handle("new-page-handle")
print(f"New handle: {updated_page.handle}")

# Change handle and create a URL redirect from the old handle to the new one
updated_page = page.change_handle("better-handle", redirect=True)
print(f"Handle changed to: {updated_page.handle}")
print("Redirect created from old handle")

Working with Page Content

Creating Rich Content

def create_rich_content_page():
    """Create a page with various content block types."""

    rich_content = {
        "time": 1672531200000,
        "blocks": [
            # Header
            {
                "type": "header",
                "data": {"text": "Welcome to Our Service", "level": 1}
            },
            # Paragraph
            {
                "type": "paragraph",
                "data": {"text": "We provide exceptional service to our customers."}
            },
            # List
            {
                "type": "list",
                "data": {
                    "style": "ordered",
                    "items": [
                        "Fast and reliable service",
                        "24/7 customer support",
                        "Competitive pricing"
                    ]
                }
            },
            # Quote
            {
                "type": "quote",
                "data": {
                    "text": "Excellence is not a skill, it's an attitude.",
                    "caption": "Ralph Marston"
                }
            },
            # Image (if you have image URLs)
            {
                "type": "image",
                "data": {
                    "file": {
                        "url": "https://example.com/service-image.jpg"
                    },
                    "caption": "Our service in action"
                }
            }
        ],
        "version": "2.28.0"
    }

    page_data = PageCreate(
        name="Service Overview",
        title="Our Premium Service",
        handle="service",
        page_type=PageType.GENERAL,
        content=rich_content
    )

    return client.pages.create(page_data)

# Usage
rich_page = create_rich_content_page()
print(f"Rich content page created: {rich_page.title}")

Iterating All Pages

# Memory-efficient iteration over all pages
for page in client.pages.iter_all(page_size=50):
    print(f"Processing page: {page.title}")

# With filtering - get all published pages
for page in client.pages.iter_all(page_size=50, published=True):
    print(f"Processing published page: {page.title}")

Async Operations

import asyncio
import konigle

async def manage_pages():
    async with konigle.AsyncClient(api_key="your-api-key") as client:
        # Create page
        page_data = PageCreate(
            name="Async Page",
            title="Page Created Asynchronously",
            page_type=PageType.GENERAL,
            content={
                "blocks": [{"type": "paragraph", "data": {"text": "Async content"}}]
            }
        )
        page = await client.pages.create(page_data)

        # List pages with filtering
        pages = await client.pages.list(
            page_size=10,
            page_type="general",
            q="async"
        )

        # Update page
        update_data = PageUpdate(title="Updated Async Page")
        updated_page = await client.pages.update(page.id, update_data)

        # Delete page
        await client.pages.delete(page.id)

asyncio.run(manage_pages())

Common Page Templates

def create_legal_page(page_type: PageType, title: str, handle: str, content_text: str):
    """Create a legal page (terms, privacy, etc.)."""
    return PageCreate(
        name=title,
        title=title,
        handle=handle,
        page_type=page_type,
        content={
            "time": 1672531200000,
            "blocks": [
                {
                    "type": "header",
                    "data": {"text": title, "level": 1}
                },
                {
                    "type": "paragraph",
                    "data": {"text": f"Last updated: {datetime.now().strftime('%B %d, %Y')}"}
                },
                {
                    "type": "paragraph",
                    "data": {"text": content_text}
                }
            ],
            "version": "2.28.0"
        },
        seo_meta=SEOMeta(
            title=f"{title} | Your Company",
            description=f"Read our {title.lower()} to understand your rights and our policies"
        ),
        show_author=False,
        exclude_from_sitemap=False
    )

# Create legal pages
from datetime import datetime

privacy_page = create_legal_page(
    PageType.PRIVACY,
    "Privacy Policy",
    "privacy",
    "This privacy policy describes how we collect, use, and protect your information."
)

terms_page = create_legal_page(
    PageType.TERMS,
    "Terms of Service",
    "terms",
    "These terms govern your use of our website and services."
)

Landing Page Template

def create_landing_page(title: str, subtitle: str, cta_text: str):
    """Create a marketing landing page."""
    return PageCreate(
        name=f"Landing - {title}",
        title=title,
        page_type=PageType.LANDING,
        subtitle=subtitle,
        content={
            "time": 1672531200000,
            "blocks": [
                {
                    "type": "header",
                    "data": {"text": title, "level": 1}
                },
                {
                    "type": "paragraph",
                    "data": {"text": subtitle}
                },
                {
                    "type": "paragraph",
                    "data": {"text": cta_text}
                }
            ],
            "version": "2.28.0"
        },
        seo_meta=SEOMeta(
            title=f"{title} | Your Company",
            description=subtitle,
            og_title=title,
            og_description=subtitle
        )
    )

# Usage
landing_page = create_landing_page(
    "Transform Your Business Today",
    "Discover how our solution can help you achieve your goals",
    "Get started with a free trial and see the difference."
)

Error Handling

from konigle.exceptions import ValidationError

def create_page_safely(page_data: PageCreate) -> bool:
    try:
        with konigle.Client(api_key="your-api-key") as client:
            page = client.pages.create(page_data)
            print(f"Successfully created page: {page.id}")
            return True

    except ValidationError as e:
        print(f"Validation failed: {e}")
        return False
    except Exception as e:
        print(f"Unexpected error: {e}")
        return False

# Test page creation
page_data = PageCreate(
    name="Test Page",
    title="Test Page Title",
    page_type=PageType.GENERAL,
    content={"blocks": [{"type": "paragraph", "data": {"text": "Test content"}}]}
)

success = create_page_safely(page_data)

Best Practices

SEO-Optimized Page Creation

def create_seo_page(name: str, title: str, handle: str, description: str, content_blocks: list):
    """Create an SEO-optimized page."""
    return PageCreate(
        name=name,
        title=title,
        handle=handle,
        page_type=PageType.GENERAL,
        content={
            "time": 1672531200000,
            "blocks": content_blocks,
            "version": "2.28.0"
        },
        seo_meta=SEOMeta(
            title=f"{title} | Your Company",
            description=description,
            keywords=f"{title.lower()},{name.lower()},your company",
            og_title=title,
            og_description=description
        ),
        exclude_from_sitemap=False
    )

# Usage
seo_page = create_seo_page(
    name="About Our Team",
    title="Meet Our Amazing Team",
    handle="team",
    description="Get to know the talented individuals behind our success",
    content_blocks=[
        {
            "type": "paragraph",
            "data": {"text": "Our team is composed of talented individuals..."}
        }
    ]
)

Batch Page Creation

# Create multiple pages efficiently
page_templates = [
    {
        "name": "About Us",
        "title": "About Our Company",
        "page_type": PageType.ABOUT,
        "content": "Learn about our company history and mission."
    },
    {
        "name": "Contact",
        "title": "Get In Touch",
        "page_type": PageType.CONTACT,
        "content": "Contact us for questions or support."
    },
    {
        "name": "FAQ",
        "title": "Frequently Asked Questions",
        "page_type": PageType.FAQ,
        "content": "Find answers to common questions."
    }
]

created_pages = []

with konigle.Client(api_key="your-api-key") as client:
    for template in page_templates:
        page_data = PageCreate(
            name=template["name"],
            title=template["title"],
            page_type=template["page_type"],
            content={
                "blocks": [{"type": "paragraph", "data": {"text": template["content"]}}]
            }
        )
        page = client.pages.create(page_data)
        created_pages.append(page)
        print(f"Created: {page.title}")

print(f"Created {len(created_pages)} pages")