mscherer 5 年之前
父节点
当前提交
897c1524dc
共有 1 个文件被更改,包括 13 次插入9 次删除
  1. 13 9
      src/View/Helper/CommonHelper.php

+ 13 - 9
src/View/Helper/CommonHelper.php

@@ -67,23 +67,27 @@ class CommonHelper extends Helper {
 	/**
 	 * Convenience method for clean ROBOTS allowance
 	 *
-	 * @param string|null $type - private/public
+	 * @param string|string[]|null $type - private/public or array of index/follow/archtive,...
 	 * @return string HTML
 	 */
-	public function metaRobots(?string $type = null): string {
+	public function metaRobots($type = null): string {
 		if ($type === null && ($meta = Configure::read('Config.robots')) !== null) {
 			$type = $meta;
 		}
-		$content = [];
-		if ($type === 'public') {
-			//$this->privatePage = false;
-			$content['robots'] = ['index', 'follow', 'noarchive'];
+		if ($type === null) {
+			$type = ['noindex', 'nofollow', 'noarchive'];
+		}
+
+		$robots = [];
+		if (is_array($type)) {
+			$robots = $type;
+		} elseif ($type === 'public') {
+			$robots = ['index', 'follow', 'noarchive'];
 		} else {
-			//$this->privatePage = true;
-			$content['robots'] = ['noindex', 'nofollow', 'noarchive'];
+			$robots = ['noindex', 'nofollow', 'noarchive'];
 		}
 
-		$return = '<meta name="robots" content="' . implode(',', $content['robots']) . '" />';
+		$return = '<meta name="robots" content="' . implode(',', $robots) . '" />';
 
 		return $return;
 	}