diff --git a/database/pagedaosqlite.cpp b/database/pagedaosqlite.cpp index 9b95ab3..b9e44a2 100644 --- a/database/pagedaosqlite.cpp +++ b/database/pagedaosqlite.cpp @@ -58,9 +58,9 @@ std::optional PageDaoSqlite::find(unsigned int id) result.pageid = id; try { - auto ps = *db << "SELECT name, lastrevision, visible FROM page WHERE id = ?"; + auto ps = *db << "SELECT name, title, lastrevision, visible FROM page WHERE id = ?"; - ps << id >> std::tie(result.name, result.current_revision, result.listed); + ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed); } catch(const sqlite::errors::no_rows &e) { @@ -97,9 +97,10 @@ void PageDaoSqlite::save(const Page &page) { try { - *db << "INSERT OR REPLACE INTO page (id, name, lastrevision, visible) VALUES((SELECT id FROM page WHERE name = " - "? OR id = ?), ?, ?, ?)" - << page.name << page.pageid << page.name << page.current_revision << page.listed; + *db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, visible) VALUES((SELECT id FROM page WHERE " + "name = " + "? OR id = ?), ?, ?, ?, ?)" + << page.name << page.pageid << page.name << page.title << page.current_revision << page.listed; } catch(sqlite::sqlite_exception &e) { @@ -183,7 +184,8 @@ std::vector PageDaoSqlite::search(std::string name, QueryOption op auto query = *db << "SELECT page.name FROM search INNER JOIN page ON search.page = page.id WHERE search MATCH ? " << ftsEscape(name); - query >> [&](std::string pagename) { + query >> [&](std::string pagename) + { SearchResult sresult; sresult.pagename = pagename; sresult.query = name; diff --git a/dynamic/dynamiccontentpostlist.cpp b/dynamic/dynamiccontentpostlist.cpp index 4b1ce25..1702541 100644 --- a/dynamic/dynamiccontentpostlist.cpp +++ b/dynamic/dynamiccontentpostlist.cpp @@ -34,7 +34,7 @@ std::string DynamicContentPostList::render() Varreplacer replacer{"{"}; replacer.addKeyValue("url", link); replacer.addKeyValue("date", date); - replacer.addKeyValue("page", pair.first); + replacer.addKeyValue("title", pageDao->find(pair.first)->title); stream << replacer.parse(postLink); } diff --git a/handlers/handlerpageedit.cpp b/handlers/handlerpageedit.cpp index cc907c9..f8b1407 100644 --- a/handlers/handlerpageedit.cpp +++ b/handlers/handlerpageedit.cpp @@ -66,6 +66,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, this->database->beginTransaction(); std::string visiblecmd = parser.extractCommand("visible", newContent); std::string rename = parser.extractCommand("rename", newContent); + std::string customtitle = parser.extractCommand("pagetitle", newContent); Page page; std::optional currentPage = pageDao.find(pagename); if(currentPage) @@ -83,6 +84,11 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, page.current_revision = current_revision; page.listed = !(visiblecmd == "0"); page.name = pagename; + page.title = customtitle; + if(page.title.empty()) + { + page.title = page.name; + } pageDao.save(page); Revision newRevision; diff --git a/page.h b/page.h index 75aca8e..d987356 100644 --- a/page.h +++ b/page.h @@ -7,6 +7,7 @@ class Page public: Page(); std::string name; + std::string title; bool listed; unsigned int current_revision; unsigned int pageid; diff --git a/setup/sqlite.sql b/setup/sqlite.sql index b685173..56c0b8c 100644 --- a/setup/sqlite.sql +++ b/setup/sqlite.sql @@ -1,4 +1,4 @@ -CREATE TABLE page(id INTEGER PRIMARY KEY, name varchar(256), lastrevision integer, visible integer DEFAULT 1); +CREATE TABLE page(id INTEGER PRIMARY KEY, name varchar(256), title varchar(1024), lastrevision integer, visible integer DEFAULT 1); CREATE TABLE user(id INTEGER PRIMARY KEY,username varchar(64), password blob, salt blob, permissions integer, enabled integer DEFAULT 1); CREATE TABLE session(id INTEGER PRIMARY KEY, csrf_token varchar(32),