Skip to content

Commit

Permalink
https://github.com/elmsln/issues/issues/1633
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Jul 27, 2023
1 parent e738a04 commit 01f5603
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 101 deletions.
203 changes: 106 additions & 97 deletions system/backend/php/lib/HAXCMSSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,14 @@ public function getManagedTemplateFiles() {
* Reprocess the files that twig helps set in their static
* form that the user is not in control of.
*/
public function rebuildManagedFiles() {
$templates = $this->getManagedTemplateFiles();
// this can't be there by default since it's a dynamic file and we only
// want to update this when we are refreshing the managed files directly
$templates['indexphp'] = 'index.php';
public function rebuildManagedFiles($templates = array()) {
// support for calling with a set of predefined templates
if (count($templates) === 0) {
$templates = $this->getManagedTemplateFiles();
// this can't be there by default since it's a dynamic file and we only
// want to update this when we are refreshing the managed files directly
$templates['indexphp'] = 'index.php';
}
$siteDirectoryPath = $this->directory . '/' . $this->manifest->metadata->site->name;
$boilerPath = HAXCMS_ROOT . '/system/boilerplate/site/';
foreach ($templates as $file) {
Expand Down Expand Up @@ -682,98 +685,104 @@ public function save() {
*/
public function updateAlternateFormats($format = NULL)
{
$siteDirectory = $this->directory . '/' . $this->manifest->metadata->site->name . '/';
if (is_null($format) || $format == 'rss') {
try {
// rip changes to feed urls
$rss = new FeedMe();
$siteDirectory =
$this->directory . '/' . $this->manifest->metadata->site->name . '/';
@file_put_contents($siteDirectory . 'rss.xml', $rss->getRSSFeed($this));
@file_put_contents(
$siteDirectory . 'atom.xml',
$rss->getAtomFeed($this)
);
} catch (Exception $e) {
// some of these XML parsers are a bit unstable
}
}
// build a sitemap if we have a domain, kinda required...
if (is_null($format) || $format == 'sitemap') {
try {
if (isset($this->manifest->metadata->site->domain)) {
$domain = $this->manifest->metadata->site->domain;
$generator = new \Icamys\SitemapGenerator\SitemapGenerator(
$domain,
$siteDirectory
);
// will create also compressed (gzipped) sitemap
$generator->createGZipFile = true;
// determine how many urls should be put into one file
// according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$generator->maxURLsPerSitemap = 50000;
// sitemap file name
$generator->sitemapFileName = "sitemap.xml";
// sitemap index file name
$generator->sitemapIndexFileName = "sitemap-index.xml";
// adding url `loc`, `lastmodified`, `changefreq`, `priority`
foreach ($this->manifest->items as $key => $item) {
if ($item->parent == null) {
$priority = '1.0';
} elseif ($item->indent == 2) {
$priority = '0.7';
} else {
$priority = '0.5';
}
$updatedTime = new DateTime();
$updatedTime->setTimestamp($item->metadata->updated);
$updatedTime->format(DateTime::ATOM);
$generator->addUrl(
$domain .
'/' .
str_replace(
'pages/',
'',
str_replace('/index.html', '', $item->location)
),
$updatedTime,
'daily',
$priority
);
}
// generating internally a sitemap
$generator->createSitemap();
// writing early generated sitemap to file
$generator->writeSitemap();
}
} catch (Exception $e) {
// some of these XML parsers are a bit unstable
}
}
if (is_null($format) || $format == 'legacy') {
// now generate a static list of links. This is so we can have legacy fail-back iframe mode in tact
@file_put_contents(
$siteDirectory . 'legacy-outline.html',
'<!DOCTYPE html>
<html lang="' . $this->getLanguage() . '">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" type="text/css" href="assets/legacy-outline.css">
</head>
<body>' .
$this->treeToNodes($this->manifest->items) .
'</body>
</html>'
);
}
if (is_null($format) || $format == 'search') {
// now generate the search index
@file_put_contents(
$siteDirectory . 'lunrSearchIndex.json',
json_encode($this->lunrSearchIndex($this->manifest->items))
);
}
$siteDirectory = $this->directory . '/' . $this->manifest->metadata->site->name . '/';
if (is_null($format) || $format == 'rss') {
try {
// rip changes to feed urls
$rss = new FeedMe();
$siteDirectory =
$this->directory . '/' . $this->manifest->metadata->site->name . '/';
@file_put_contents($siteDirectory . 'rss.xml', $rss->getRSSFeed($this));
@file_put_contents(
$siteDirectory . 'atom.xml',
$rss->getAtomFeed($this)
);
} catch (Exception $e) {
// some of these XML parsers are a bit unstable
}
}
// build a sitemap if we have a domain, kinda required...
if (is_null($format) || $format == 'sitemap') {
try {
if (isset($this->manifest->metadata->site->domain)) {
$domain = $this->manifest->metadata->site->domain;
$generator = new \Icamys\SitemapGenerator\SitemapGenerator(
$domain,
$siteDirectory
);
// will create also compressed (gzipped) sitemap
$generator->createGZipFile = true;
// determine how many urls should be put into one file
// according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$generator->maxURLsPerSitemap = 50000;
// sitemap file name
$generator->sitemapFileName = "sitemap.xml";
// sitemap index file name
$generator->sitemapIndexFileName = "sitemap-index.xml";
// adding url `loc`, `lastmodified`, `changefreq`, `priority`
foreach ($this->manifest->items as $key => $item) {
if ($item->parent == null) {
$priority = '1.0';
} elseif ($item->indent == 2) {
$priority = '0.7';
} else {
$priority = '0.5';
}
$updatedTime = new DateTime();
$updatedTime->setTimestamp($item->metadata->updated);
$updatedTime->format(DateTime::ATOM);
$generator->addUrl(
$domain .
'/' .
str_replace(
'pages/',
'',
str_replace('/index.html', '', $item->location)
),
$updatedTime,
'daily',
$priority
);
}
// generating internally a sitemap
$generator->createSitemap();
// writing early generated sitemap to file
$generator->writeSitemap();
}
} catch (Exception $e) {
// some of these XML parsers are a bit unstable
}
}
if (is_null($format) || $format == 'legacy') {
// now generate a static list of links. This is so we can have legacy fail-back iframe mode in tact
@file_put_contents(
$siteDirectory . 'legacy-outline.html',
'<!DOCTYPE html>
<html lang="' . $this->getLanguage() . '">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" type="text/css" href="assets/legacy-outline.css">
</head>
<body>' .
$this->treeToNodes($this->manifest->items) .
'</body>
</html>'
);
}
if (is_null($format) || $format == 'search') {
// now generate the search index
@file_put_contents(
$siteDirectory . 'lunrSearchIndex.json',
json_encode($this->lunrSearchIndex($this->manifest->items))
);
}
// rebuild the service worker's hashed cache index because this file updated
// this way users getting cached copies from local device will be informed
// that this page updated since their last visit
if (is_null($format) || $format == 'service-worker') {
$this->rebuildManagedFiles(array('sw' => 'service-worker.js'));
}
}
/**
* Create Lunr.js style search index
Expand Down
8 changes: 6 additions & 2 deletions system/backend/php/lib/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,9 @@ public function createNode() {
}
}
}
$site->gitCommit('Page added:' . $item->title . ' (' . $item->id . ')');
$site->gitCommit('Page added:' . $item->title . ' (' . $item->id . ')');
// update the alternate formats as a new page exists
$site->updateAlternateFormats();
}
return array(
'status' => 200,
Expand Down Expand Up @@ -2070,7 +2072,9 @@ public function createSite() {
$cssvar = '--simple-colors-default-theme-light-blue-7';
}
$schema->metadata->theme->variables->cssVariable = $cssvar;
$schema->metadata->site->settings->lang = 'en';
$schema->metadata->site->settings = new stdClass();
$schema->metadata->site->settings->lang = 'en-US';
$schema->metadata->site->settings->publishPagesOn = true;
$schema->metadata->site->created = time();
$schema->metadata->site->updated = time();
// check for publishing settings being set globally in HAXCMS
Expand Down
4 changes: 2 additions & 2 deletions system/coreConfig/siteFields.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
{
"property": "manifest-metadata-site-settings-publishPagesOn",
"title": "Hide unpublished pages",
"description": "Check the box to hide unpublished pages",
"description": "Uncheck this box if you want to show unpublished pages to the public",
"inputMethod": "boolean",
"icon": "icons:link"
},
Expand All @@ -164,7 +164,7 @@
{
"property": "manifest-metadata-site-settings-forceUpgrade",
"title": "Force browser upgrade",
"description": "Force users viewing the site to have evergreen browsers (not recommended)",
"description": "Force users viewing the site to have evergreen browsers and ask to upgrade if they don't",
"inputMethod": "boolean",
"icon": "icons:link"
}
Expand Down

0 comments on commit 01f5603

Please sign in to comment.