From 98d05388688795d9735720b085ea02ed32da34c0 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 23 Oct 2015 10:23:01 -0600 Subject: [PATCH] Option to allow all hidden files/folders #306 --- system/blueprints/config/system.yaml | 11 +++++++++++ system/config/system.yaml | 1 + system/src/Grav/Common/Page/Pages.php | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 46f235010..fca66cd30 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -175,6 +175,17 @@ form: validate: type: bool + pages.ignore_hidden: + type: toggle + label: PLUGIN_ADMIN.IGNORE_HIDDEN + help: PLUGIN_ADMIN.IGNORE_HIDDEN_HELP + highlight: 1 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + pages.ignore_files: type: selectize size: large diff --git a/system/config/system.yaml b/system/config/system.yaml index b60e55d82..366d1e549 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -51,6 +51,7 @@ pages: redirect_trailing_slash: true # Handle automatically or 301 redirect a trailing / URL ignore_files: [.DS_Store] # Files to ignore in Pages ignore_folders: [.git, .idea] # Folders to ignore in Pages + ignore_hidden: true # Ignore all Hidden files and folders url_taxonomy_filters: true # Enable auto-magic URL-based taxonomy filters for page collections cache: diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 20a24f912..ccb7530d1 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -65,6 +65,7 @@ class Pages protected $ignore_files; protected $ignore_folders; + protected $ignore_hidden; /** * @var Types @@ -108,6 +109,7 @@ class Pages $config = $this->grav['config']; $this->ignore_files = $config->get('system.pages.ignore_files'); $this->ignore_folders = $config->get('system.pages.ignore_folders'); + $this->ignore_hidden = $config->get('system.pages.ignore_hidden'); $this->buildPages(); } @@ -702,6 +704,13 @@ class Pages foreach (new \FilesystemIterator($directory) as $file) { $name = $file->getFilename(); + // Ignore all hidden files if set. + if ($this->ignore_hidden) { + if ($name && $name[0] == '.') { + continue; + } + } + if ($file->isFile()) { // Update the last modified if it's newer than already found if (!in_array($file->getBasename(), $this->ignore_files) && ($modified = $file->getMTime()) > $last_modified) {