# Path: akamatsu/models.py
# class Page(BaseModel):
#     """Model for dynamic pages.
# 
#     Pages may be written in markdown (default) or in html. Security should
#     be taken into consideration when writing html.
# 
#     The `<head>` can be extended (e.g. to add some custom JS scripts) when
#     writing pages in html.
# 
#     Pages can "ghost" other pages, meaning that accessing a ghost page will
#     redirect to the page being ghosted.
# 
#     Attributes:
#         id (int): Unique page ID.
#         ghosted_id (int): ID of the page the browser will be redirected to
#             when accessing this page. If set to `None`, this page will not be
#             a ghost page.
#         title (str): Title of the page.
#         mini (str): Optional text to show at the top of the page.
#         route (str): Route to this page. Must be unique.
#         custom_head (str): Add custom html to the `<head>` of the template.
#         content (str): Main content of the page. This can be written in markdown
#             or html.
#         is_published (bool): Whether the page is published.
#         comments_enabled (bool): Whether comments are enabled for this page.
#         last_updated (datetime): UTC datetime in which the page was last edited.
#     """
#     __tablename__ = 'pages'
# 
#     id = db.Column(db.Integer, primary_key=True)
# 
#     ghosted_id = db.Column(
#         db.Integer,
#         db.ForeignKey('pages.id', onupdate='CASCADE', ondelete='CASCADE'),
#         nullable=True
#     )
#     title = db.Column(db.String(255), nullable=False)
#     mini = db.Column(db.String(50), nullable=False)
#     route = db.Column(db.String(255), nullable=False, unique=True)
#     custom_head = db.Column(db.Text, nullable=True)
#     content = db.Column(db.Text, nullable=False)
#     is_published = db.Column(db.Boolean, default=False)
#     comments_enabled = db.Column(db.Boolean, default=False)
#     last_updated = db.Column(db.DateTime)
# 
#     # Relationships
#     ghosts = db.relationship(
#         'Page',
#         cascade='all',
#         backref=db.backref('ghosted', remote_side='Page.id'),
#         collection_class=set
#     )
# 
#     def __str__(self):
#         return self.title


from flask import Blueprint, abort, redirect, render_template, url_for
from akamatsu.models import Page




bp_pages = Blueprint('pages', __name__)


@bp_pages.route('/')
def root():
    """Load the root page."""
    page = (
        Page.query
        .filter_by(route='/')
        .filter_by(is_published=True)
    ).first_or_404()

    return render_template('pages/show.html', page=page)


@bp_pages.route('/<path:route>')
def show(route):
    """Show the page identified by the given route.

    Args:
        route (path): Route to the page.
    """
    # Mind root slash
    route = '/' + route

    page = (

# Path: akamatsu/models.py
# class Page(BaseModel):
#     """Model for dynamic pages.
# 
#     Pages may be written in markdown (default) or in html. Security should
#     be taken into consideration when writing html.
# 
#     The `<head>` can be extended (e.g. to add some custom JS scripts) when
#     writing pages in html.
# 
#     Pages can "ghost" other pages, meaning that accessing a ghost page will
#     redirect to the page being ghosted.
# 
#     Attributes:
#         id (int): Unique page ID.
#         ghosted_id (int): ID of the page the browser will be redirected to
#             when accessing this page. If set to `None`, this page will not be
#             a ghost page.
#         title (str): Title of the page.
#         mini (str): Optional text to show at the top of the page.
#         route (str): Route to this page. Must be unique.
#         custom_head (str): Add custom html to the `<head>` of the template.
#         content (str): Main content of the page. This can be written in markdown
#             or html.
#         is_published (bool): Whether the page is published.
#         comments_enabled (bool): Whether comments are enabled for this page.
#         last_updated (datetime): UTC datetime in which the page was last edited.
#     """
#     __tablename__ = 'pages'
# 
#     id = db.Column(db.Integer, primary_key=True)
# 
#     ghosted_id = db.Column(
#         db.Integer,
#         db.ForeignKey('pages.id', onupdate='CASCADE', ondelete='CASCADE'),
#         nullable=True
#     )
#     title = db.Column(db.String(255), nullable=False)
#     mini = db.Column(db.String(50), nullable=False)
#     route = db.Column(db.String(255), nullable=False, unique=True)
#     custom_head = db.Column(db.Text, nullable=True)
#     content = db.Column(db.Text, nullable=False)
#     is_published = db.Column(db.Boolean, default=False)
#     comments_enabled = db.Column(db.Boolean, default=False)
#     last_updated = db.Column(db.DateTime)
# 
#     # Relationships
#     ghosts = db.relationship(
#         'Page',
#         cascade='all',
#         backref=db.backref('ghosted', remote_side='Page.id'),
#         collection_class=set
#     )
# 
#     def __str__(self):
#         return self.title


# Path: akamatsu/views/pages.py
from flask import Blueprint, abort, redirect, render_template, url_for
from akamatsu.models import Page





bp_pages = Blueprint('pages', __name__)


@bp_pages.route('/')
def root():
    """Load the root page."""
    page = (
        Page.query
        .filter_by(route='/')
        .filter_by(is_published=True)
    ).first_or_404()

    return render_template('pages/show.html', page=page)


@bp_pages.route('/<path:route>')
def show(route):
    """Show the page identified by the given route.

    Args:
        route (path): Route to the page.
    """
    # Mind root slash
    route = '/' + route

    page = (

        Page.query