diff --git a/controller/Controller.class.php b/controller/Controller.class.php index ec08eba2..a531d4ce 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -73,15 +73,21 @@ class Controller case '/art': return static::redirect('/what'); default: - $blogPattern = '#^' . BlogActions::URL_STEM . '(/|$)#'; - if (preg_match($blogPattern, $uri)) + $newsPattern = '#^' . ContentActions::URL_NEWS . '(/|$)#'; + if (preg_match($newsPattern, $uri)) { - $slug = preg_replace($blogPattern, '', $uri); - if ($slug == BlogActions::RSS_SLUG) + $slug = preg_replace($newsPattern, '', $uri); + if ($slug == ContentActions::RSS_SLUG) { - return BlogActions::executeRss(); + return ContentActions::executeRss(); } - return $slug ? BlogActions::executePost($slug) : BlogActions::executeIndex(); + return $slug ? ContentActions::executePost($uri) : ContentActions::executeNews(); + } + $faqPattern = '#^' . ContentActions::URL_FAQ . '(/|$)#'; + if (preg_match($faqPattern, $uri)) + { + $slug = preg_replace($faqPattern, '', $uri); + return $slug ? ContentActions::executePost($uri) : ContentActions::executeFaq(); } $noSlashUri = ltrim($uri, '/'); if (View::exists('page/' . $noSlashUri)) diff --git a/controller/action/BlogActions.class.php b/controller/action/BlogActions.class.php deleted file mode 100644 index 171ce5ba..00000000 --- a/controller/action/BlogActions.class.php +++ /dev/null @@ -1,62 +0,0 @@ -getDate()->format('Y-m-d'), $a->getDate()->format('Y-m-d')); - }); - $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; - return ['blog/index', [ - 'posts' => $posts, - 'page' => $page, - View::LAYOUT_PARAMS => [ - 'showRssLink' => true - ] - ]]; - } - - public static function executeRss() - { - $posts = Blog::getPosts(); - usort($posts, function(Post $a, Post $b) { - return strcasecmp($b->getDate()->format('Y-m-d'), $a->getDate()->format('Y-m-d')); - }); - return ['blog/rss', [ - 'posts' => array_slice($posts, 0, 10), - '_no_layout' => true - ], [ - 'Content-Type' => 'text/xml; charset=utf-8' - ]]; - } - - public static function executePost($slug) - { - $post = Blog::getPost($slug); - if (!$post) - { - return ['page/404', []]; - } - return ['blog/post', [ - 'post' => $post, - View::LAYOUT_PARAMS => [ - 'showRssLink' => true - ] - ]]; - } - - public static function prepareAuthorPartial(array $vars) - { - $post = $vars['post']; - return [ - 'authorName' => $post->getAuthorName(), - 'photoImgSrc' => $post->getAuthorPhoto(), - 'authorBioHtml' => $post->getAuthorBioHtml() - ]; - } -} diff --git a/controller/action/ContentActions.class.php b/controller/action/ContentActions.class.php index d80cdd0e..fc75a5af 100644 --- a/controller/action/ContentActions.class.php +++ b/controller/action/ContentActions.class.php @@ -7,6 +7,12 @@ */ class ContentActions extends Actions { + const RSS_SLUG = 'rss.xml', + URL_NEWS = '/news', + URL_FAQ = '/faq', + VIEW_FOLDER_NEWS = ROOT_DIR . '/posts/news', + VIEW_FOLDER_FAQ = ROOT_DIR . '/posts/faq'; + public static function executeHome() { return ['page/home', [ @@ -14,4 +20,60 @@ class ContentActions extends Actions 'totalPeople' => CreditApi::getTotalPeople() ]]; } + + public static function executeFaq() + { + $posts = Post::find(static::VIEW_FOLDER_FAQ); + return ['content/faq', [ + 'posts' => $posts + ]]; + } + + public static function executeNews() + { + $posts = Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC); + return ['content/news', [ + 'posts' => $posts, + View::LAYOUT_PARAMS => [ + 'showRssLink' => true + ] + ]]; + } + + + public static function executeRss() + { + $posts = Post::find(static::VIEW_FOLDER_NEWS, Post::SORT_DATE_DESC); + return ['content/rss', [ + 'posts' => array_slice($posts, 0, 10), + '_no_layout' => true + ], [ + 'Content-Type' => 'text/xml; charset=utf-8' + ]]; + } + + public static function executePost($relativeUri) + { + $post = Post::load(ltrim($relativeUri, '/')); + if (!$post) + { + return ['page/404', []]; + } + return ['content/post', [ + 'post' => $post, + View::LAYOUT_PARAMS => [ + 'showRssLink' => true + ] + ]]; + } + + public static function preparePostAuthorPartial(array $vars) + { + $post = $vars['post']; + return [ + 'authorName' => $post->getAuthorName(), + 'photoImgSrc' => $post->getAuthorPhoto(), + 'authorBioHtml' => $post->getAuthorBioHtml() + ]; + } } diff --git a/model/Blog.class.php b/model/Blog.class.php deleted file mode 100644 index 856bc327..00000000 --- a/model/Blog.class.php +++ /dev/null @@ -1,53 +0,0 @@ -category = $category; $this->slug = $slug; $this->markdown = $markdown; $this->title = isset($frontMatter['title']) ? $frontMatter['title'] : null; @@ -22,9 +52,30 @@ class Post $this->isCoverLight = isset($frontMatter['cover-light']) && $frontMatter['cover-light'] == 'true'; } + public static function find($folder, $sort = null) + { + $posts = []; + foreach(glob(rtrim($folder, '/') . '/*.md') as $file) + { + $posts[] = static::load($file); + } + if ($sort) + { + switch ($sort) + { + case static::SORT_DATE_DESC: + usort($posts, function(Post $a, Post $b) { + return strcasecmp($b->getDate()->format('Y-m-d'), $a->getDate()->format('Y-m-d')); + }); + break; + } + } + return $posts; + } + public function getRelativeUrl() { - return BlogActions::URL_STEM . '/' . $this->slug; + return $this->category . '/' . $this->slug; } public function getSlug() @@ -79,21 +130,26 @@ class Post public function getPostNum() { - return array_search($this->getSlug(), array_keys(Blog::getSlugMap())); + return array_search($this->getSlug(), array_keys(static::getSlugMap($this->category))); } public function getPrevPost() { - $slugs = array_keys(Blog::getSlugMap()); + $slugs = array_keys(Post::getSlugMap($this->category)); $postNum = $this->getPostNum(); - return $postNum === false || $postNum === 0 ? null : Blog::getPost($slugs[$postNum-1]); + return $postNum === false || $postNum === 0 ? null : Post::load($this->category . '/' . $slugs[$postNum-1]); } public function getNextPost() { - $slugs = array_keys(Blog::getSlugMap()); + $slugs = array_keys(Post::getSlugMap($this->category)); $postNum = $this->getPostNum(); - return $postNum === false || $postNum >= count($slugs)-1 ? null : Blog::getPost($slugs[$postNum+1]); + return $postNum === false || $postNum >= count($slugs)-1 ? null : Post::load($this->category . '/' . $slugs[$postNum+1]); + } + + public function hasAuthor() + { + return $this->author !== null; } public function getAuthorName() @@ -108,6 +164,9 @@ class Post return 'Jimmy Kiselak'; case 'jack': return 'Jack Robison'; + case null: + case '': + return ''; case 'lbry': default: return 'Samuel Bryan'; @@ -221,4 +280,22 @@ class Post return $string; } + + public static function getSlugFromFilename($filename) + { + return strtolower(preg_replace('#^\d+\-#', '', basename(trim($filename), '.md'))); + } + + public static function getSlugMap($category) + { + if (!isset(static::$slugMap[$category])) + { + static::$slugMap[$category] = []; + foreach(glob(ROOT_DIR . '/posts/' . $category . '/*.md') as $file) + { + static::$slugMap[$category][static::getSlugFromFilename($file)] = $file; + } + } + return static::$slugMap[$category]; + } } \ No newline at end of file diff --git a/view/37-art.md b/posts/37-art.md similarity index 100% rename from view/37-art.md rename to posts/37-art.md diff --git a/posts/faq/is-lbry-open-source.md b/posts/faq/is-lbry-open-source.md new file mode 100644 index 00000000..42cb52d4 --- /dev/null +++ b/posts/faq/is-lbry-open-source.md @@ -0,0 +1,6 @@ +--- +title: Is LBRY Open Source? +date: '2015-05-24 16:00:00' +--- + +All of the code we have written for LBRY is open source - even this very website! You can access it on [GitHub](https://github.com/lbryio/). \ No newline at end of file diff --git a/view/posts/01-the-lbry-opens.md b/posts/news/01-the-lbry-opens.md similarity index 100% rename from view/posts/01-the-lbry-opens.md rename to posts/news/01-the-lbry-opens.md diff --git a/view/posts/02-as-reddit-burns-it-powers-the-world.md b/posts/news/02-as-reddit-burns-it-powers-the-world.md similarity index 100% rename from view/posts/02-as-reddit-burns-it-powers-the-world.md rename to posts/news/02-as-reddit-burns-it-powers-the-world.md diff --git a/view/posts/03-5-questions-about-lbry.md b/posts/news/03-5-questions-about-lbry.md similarity index 100% rename from view/posts/03-5-questions-about-lbry.md rename to posts/news/03-5-questions-about-lbry.md diff --git a/view/posts/04-meet-the-lbry-founders.md b/posts/news/04-meet-the-lbry-founders.md similarity index 100% rename from view/posts/04-meet-the-lbry-founders.md rename to posts/news/04-meet-the-lbry-founders.md diff --git a/view/posts/06-lbry-promo-video-raw-footage.md b/posts/news/06-lbry-promo-video-raw-footage.md similarity index 100% rename from view/posts/06-lbry-promo-video-raw-footage.md rename to posts/news/06-lbry-promo-video-raw-footage.md diff --git a/view/posts/09-introducing-lbry-the-bitcoin-of-content.md b/posts/news/09-introducing-lbry-the-bitcoin-of-content.md similarity index 100% rename from view/posts/09-introducing-lbry-the-bitcoin-of-content.md rename to posts/news/09-introducing-lbry-the-bitcoin-of-content.md diff --git a/view/posts/10-slides-from-media-demo.md b/posts/news/10-slides-from-media-demo.md similarity index 100% rename from view/posts/10-slides-from-media-demo.md rename to posts/news/10-slides-from-media-demo.md diff --git a/view/posts/11-testimony-to-subcommittee-on-hb552-to-legalize-bitcoin-for-payments-of-taxes-and-fees.md b/posts/news/11-testimony-to-subcommittee-on-hb552-to-legalize-bitcoin-for-payments-of-taxes-and-fees.md similarity index 100% rename from view/posts/11-testimony-to-subcommittee-on-hb552-to-legalize-bitcoin-for-payments-of-taxes-and-fees.md rename to posts/news/11-testimony-to-subcommittee-on-hb552-to-legalize-bitcoin-for-payments-of-taxes-and-fees.md diff --git a/view/posts/12-why-not-use-bitcoin-a-dialogue.md b/posts/news/12-why-not-use-bitcoin-a-dialogue.md similarity index 100% rename from view/posts/12-why-not-use-bitcoin-a-dialogue.md rename to posts/news/12-why-not-use-bitcoin-a-dialogue.md diff --git a/view/posts/13-mike-vine-joins-lbry-as-technology-evangelist-2.md b/posts/news/13-mike-vine-joins-lbry-as-technology-evangelist-2.md similarity index 100% rename from view/posts/13-mike-vine-joins-lbry-as-technology-evangelist-2.md rename to posts/news/13-mike-vine-joins-lbry-as-technology-evangelist-2.md diff --git a/view/posts/14-lbry-gets-content-creators-out-of-precarious-position-daily-decrypts-amanda-b-johnson.md b/posts/news/14-lbry-gets-content-creators-out-of-precarious-position-daily-decrypts-amanda-b-johnson.md similarity index 100% rename from view/posts/14-lbry-gets-content-creators-out-of-precarious-position-daily-decrypts-amanda-b-johnson.md rename to posts/news/14-lbry-gets-content-creators-out-of-precarious-position-daily-decrypts-amanda-b-johnson.md diff --git a/view/posts/15-renowned-ip-attorney-kinsella-joins-lbry-cryptoapp-as-legal-advisor.md b/posts/news/15-renowned-ip-attorney-kinsella-joins-lbry-cryptoapp-as-legal-advisor.md similarity index 100% rename from view/posts/15-renowned-ip-attorney-kinsella-joins-lbry-cryptoapp-as-legal-advisor.md rename to posts/news/15-renowned-ip-attorney-kinsella-joins-lbry-cryptoapp-as-legal-advisor.md diff --git a/view/posts/16-digging-into-lbry.md b/posts/news/16-digging-into-lbry.md similarity index 100% rename from view/posts/16-digging-into-lbry.md rename to posts/news/16-digging-into-lbry.md diff --git a/view/posts/17-rpi-hackers-meet-lbry-rcos-presentation.md b/posts/news/17-rpi-hackers-meet-lbry-rcos-presentation.md similarity index 100% rename from view/posts/17-rpi-hackers-meet-lbry-rcos-presentation.md rename to posts/news/17-rpi-hackers-meet-lbry-rcos-presentation.md diff --git a/view/posts/18-its-time-to-liberate-anne-franks-diary.md b/posts/news/18-its-time-to-liberate-anne-franks-diary.md similarity index 100% rename from view/posts/18-its-time-to-liberate-anne-franks-diary.md rename to posts/news/18-its-time-to-liberate-anne-franks-diary.md diff --git a/view/posts/19-free-lbry-credits-come-and-get-em.md b/posts/news/19-free-lbry-credits-come-and-get-em.md similarity index 100% rename from view/posts/19-free-lbry-credits-come-and-get-em.md rename to posts/news/19-free-lbry-credits-come-and-get-em.md diff --git a/view/posts/20-open-a-valve-to-gush-classic-movies.md b/posts/news/20-open-a-valve-to-gush-classic-movies.md similarity index 100% rename from view/posts/20-open-a-valve-to-gush-classic-movies.md rename to posts/news/20-open-a-valve-to-gush-classic-movies.md diff --git a/view/posts/21-gmu-economist-alex-tabarrok-joins-lbry.md b/posts/news/21-gmu-economist-alex-tabarrok-joins-lbry.md similarity index 100% rename from view/posts/21-gmu-economist-alex-tabarrok-joins-lbry.md rename to posts/news/21-gmu-economist-alex-tabarrok-joins-lbry.md diff --git a/view/posts/22-building-the-web-3-0-decentralizing-content-in-an-age-of-centralization.md b/posts/news/22-building-the-web-3-0-decentralizing-content-in-an-age-of-centralization.md similarity index 100% rename from view/posts/22-building-the-web-3-0-decentralizing-content-in-an-age-of-centralization.md rename to posts/news/22-building-the-web-3-0-decentralizing-content-in-an-age-of-centralization.md diff --git a/view/posts/23-bravenewcoin.md b/posts/news/23-bravenewcoin.md similarity index 100% rename from view/posts/23-bravenewcoin.md rename to posts/news/23-bravenewcoin.md diff --git a/view/posts/24-our-christmas-surprise.md b/posts/news/24-our-christmas-surprise.md similarity index 100% rename from view/posts/24-our-christmas-surprise.md rename to posts/news/24-our-christmas-surprise.md diff --git a/view/posts/25-huemer-joins-lbry-ethical-advisor.md b/posts/news/25-huemer-joins-lbry-ethical-advisor.md similarity index 100% rename from view/posts/25-huemer-joins-lbry-ethical-advisor.md rename to posts/news/25-huemer-joins-lbry-ethical-advisor.md diff --git a/view/posts/26-jack-robison-escaped-60-years-in-prison-now-hes-revolutionizing-the-internet.md b/posts/news/26-jack-robison-escaped-60-years-in-prison-now-hes-revolutionizing-the-internet.md similarity index 100% rename from view/posts/26-jack-robison-escaped-60-years-in-prison-now-hes-revolutionizing-the-internet.md rename to posts/news/26-jack-robison-escaped-60-years-in-prison-now-hes-revolutionizing-the-internet.md diff --git a/view/posts/27-lbry-adds-chief-growth-officer-josh-finer.md b/posts/news/27-lbry-adds-chief-growth-officer-josh-finer.md similarity index 100% rename from view/posts/27-lbry-adds-chief-growth-officer-josh-finer.md rename to posts/news/27-lbry-adds-chief-growth-officer-josh-finer.md diff --git a/view/posts/28-the-dmcas-chilling-effect-on-security-research-and-innovation.md b/posts/news/28-the-dmcas-chilling-effect-on-security-research-and-innovation.md similarity index 100% rename from view/posts/28-the-dmcas-chilling-effect-on-security-research-and-innovation.md rename to posts/news/28-the-dmcas-chilling-effect-on-security-research-and-innovation.md diff --git a/view/posts/29-lbry-app-sneak-peak-big-questions-answered-lbry-on-blocktalk-last-night.md b/posts/news/29-lbry-app-sneak-peak-big-questions-answered-lbry-on-blocktalk-last-night.md similarity index 100% rename from view/posts/29-lbry-app-sneak-peak-big-questions-answered-lbry-on-blocktalk-last-night.md rename to posts/news/29-lbry-app-sneak-peak-big-questions-answered-lbry-on-blocktalk-last-night.md diff --git a/view/posts/30-try-lbry-on-os-x-el-capitan.md b/posts/news/30-try-lbry-on-os-x-el-capitan.md similarity index 100% rename from view/posts/30-try-lbry-on-os-x-el-capitan.md rename to posts/news/30-try-lbry-on-os-x-el-capitan.md diff --git a/view/posts/31-annefrank2.md b/posts/news/31-annefrank2.md similarity index 100% rename from view/posts/31-annefrank2.md rename to posts/news/31-annefrank2.md diff --git a/view/posts/32-if-lbry-succeeds-humanity-wins-lbry-ceo-on-lions-of-liberty-podcast.md b/posts/news/32-if-lbry-succeeds-humanity-wins-lbry-ceo-on-lions-of-liberty-podcast.md similarity index 100% rename from view/posts/32-if-lbry-succeeds-humanity-wins-lbry-ceo-on-lions-of-liberty-podcast.md rename to posts/news/32-if-lbry-succeeds-humanity-wins-lbry-ceo-on-lions-of-liberty-podcast.md diff --git a/view/posts/33-zarghamjoins.md b/posts/news/33-zarghamjoins.md similarity index 100% rename from view/posts/33-zarghamjoins.md rename to posts/news/33-zarghamjoins.md diff --git a/view/posts/35-why-doesnt-lbry-just-use-bitcoin.md b/posts/news/35-why-doesnt-lbry-just-use-bitcoin.md similarity index 100% rename from view/posts/35-why-doesnt-lbry-just-use-bitcoin.md rename to posts/news/35-why-doesnt-lbry-just-use-bitcoin.md diff --git a/view/posts/36-built-for-artists-by-autists-lbry-takes-autism-personally.md b/posts/news/36-built-for-artists-by-autists-lbry-takes-autism-personally.md similarity index 100% rename from view/posts/36-built-for-artists-by-autists-lbry-takes-autism-personally.md rename to posts/news/36-built-for-artists-by-autists-lbry-takes-autism-personally.md diff --git a/view/posts/38-information-gatekeepers-make-our-culture-sick.md b/posts/news/38-information-gatekeepers-make-our-culture-sick.md similarity index 100% rename from view/posts/38-information-gatekeepers-make-our-culture-sick.md rename to posts/news/38-information-gatekeepers-make-our-culture-sick.md diff --git a/view/posts/39-bandcamp-cool-growing-but-still-take-15-percent.md b/posts/news/39-bandcamp-cool-growing-but-still-take-15-percent.md similarity index 100% rename from view/posts/39-bandcamp-cool-growing-but-still-take-15-percent.md rename to posts/news/39-bandcamp-cool-growing-but-still-take-15-percent.md diff --git a/view/posts/40-tipping-in-LBC.md b/posts/news/40-tipping-in-LBC.md similarity index 100% rename from view/posts/40-tipping-in-LBC.md rename to posts/news/40-tipping-in-LBC.md diff --git a/view/posts/41-apple-lost-my-music.md b/posts/news/41-apple-lost-my-music.md similarity index 100% rename from view/posts/41-apple-lost-my-music.md rename to posts/news/41-apple-lost-my-music.md diff --git a/view/posts/42-bittorrents-new-streaming-service.md b/posts/news/42-bittorrents-new-streaming-service.md similarity index 100% rename from view/posts/42-bittorrents-new-streaming-service.md rename to posts/news/42-bittorrents-new-streaming-service.md diff --git a/view/template/blog/_author.php b/view/template/content/_postAuthor.php similarity index 100% rename from view/template/blog/_author.php rename to view/template/content/_postAuthor.php diff --git a/view/template/content/faq.php b/view/template/content/faq.php new file mode 100644 index 00000000..6241b730 --- /dev/null +++ b/view/template/content/faq.php @@ -0,0 +1,13 @@ + + false]) ?> +
+
+

Frequently Asked Questions

+ + + +
> +
+ diff --git a/view/template/blog/index.php b/view/template/content/news.php similarity index 100% rename from view/template/blog/index.php rename to view/template/content/news.php diff --git a/view/template/blog/post.php b/view/template/content/post.php similarity index 91% rename from view/template/blog/post.php rename to view/template/content/post.php index 108494c9..90bad16d 100644 --- a/view/template/blog/post.php +++ b/view/template/content/post.php @@ -9,7 +9,7 @@

getTitle()) ?>

getAuthorName() ?> - • + hasAuthor() ? '•' : '' ?> getDate()->format('M j') ?>
@@ -51,9 +51,11 @@ - $post - ]) ?> + hasAuthor()): ?> + $post + ]) ?> + diff --git a/view/template/blog/rss.php b/view/template/content/rss.php similarity index 83% rename from view/template/blog/rss.php rename to view/template/content/rss.php index 4577171f..59d571f0 100644 --- a/view/template/blog/rss.php +++ b/view/template/content/rss.php @@ -2,12 +2,12 @@ LBRY News - https://lbry.io + https://lbry.io Recent news about LBRY https://github.com/lbryio/lbry.io en Sat, 07 Sep 2002 09:42:31 GMT ?> - + <?php echo htmlspecialchars($post->getTitle()) ?> diff --git a/view/template/layout/basic.php b/view/template/layout/basic.php index f71740c3..dc7c71bc 100644 --- a/view/template/layout/basic.php +++ b/view/template/layout/basic.php @@ -26,7 +26,7 @@ - + diff --git a/web/scss/_blog.scss b/web/scss/_blog.scss index 4ba8ad5d..4e9d2c84 100644 --- a/web/scss/_blog.scss +++ b/web/scss/_blog.scss @@ -19,7 +19,6 @@ .post-header { margin-bottom: $spacing-vertical * 2; - min-height: 100vh; &.no-cover1 { // diagonal stripes background-color: $color-primary; @@ -79,6 +78,15 @@ @media (min-height: 500px) { .post-header { min-height: 500px; + &:not(.with-cover) + { + min-height: 250px; + } + } +} +@media (max-height: 500px) { + .post-header { + min-height: 100vh; } }