From 8ad115b04a68c97f5e7d4f9c23f8aba1801dd527 Mon Sep 17 00:00:00 2001 From: sagaii Date: Sat, 13 Jan 2018 01:54:44 +0800 Subject: [PATCH 1/3] add function removeAddressFirstSlash & AddAddressTwodots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // 去除 /和//造成的链接错误 --- app/controllers/Gitblog.php | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/app/controllers/Gitblog.php b/app/controllers/Gitblog.php index e54e073..4daf847 100644 --- a/app/controllers/Gitblog.php +++ b/app/controllers/Gitblog.php @@ -28,6 +28,57 @@ function __construct() $this->configFile = str_replace("\\", "/", dirname(APPPATH)) . '/' . GB_CONF_FILE; $this->blogPath = str_replace("\\", "/", dirname(APPPATH)) . '/blog/'; } + + + // 去除 /和//造成的链接错误 + + private function removeAddressFirstSlash($fileContent){ + + $htmlContent=$fileContent; + + //处理 //开头的 href + $htmlContent= preg_replace( '/href\s*=\s*\"\/\/|\'\/\//is','href="http://',$htmlContent); + + //处理href + $htmlContent= preg_replace( '/href\s*=\s*\"\/|\'\//is','href="',$htmlContent); + + + //处理 //开头的 src + $htmlContent= preg_replace( '/src\s*=\s*\"\/\/|\'\/\//is','src="http://',$htmlContent); + + //处理src + $htmlContent= preg_replace( '/src\s*=\s*\"\/|\'\//is','src="',$htmlContent); + + + $fileContent=$htmlContent; + return $fileContent; + + } + + private function AddAddressTwodots($fileContent){ + + $htmlContent=$fileContent; + + //处理 //开头的 href + $htmlContent= preg_replace( '/href\s*=\s*\"\/\/|\'\/\//is','href="http://',$htmlContent); + + //处理href + $htmlContent= preg_replace( '/href\s*=\s*\"\/|\'\//is','href="../',$htmlContent); + + + //处理 //开头的 src + $htmlContent= preg_replace( '/src\s*=\s*\"\/\/|\'\/\//is','src="http://',$htmlContent); + + //处理src + $htmlContent= preg_replace( '/src\s*=\s*\"\/|\'\//is','src="../',$htmlContent); + + + $fileContent=$htmlContent; + return $fileContent; + + } + + //导出网站 public function exportSite() @@ -55,12 +106,15 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + $fileContent=$this->removeAddressFirstSlash($fileContent); write_file($filePath . $pageNo . ".html", $fileContent); if ($pageNo == 1) { if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + //echo "fileconent:". $fileContent; + $fileContent=$this->removeAddressFirstSlash($fileContent); write_file(GB_SITE_DIR . "/index.html", $fileContent); } } @@ -85,6 +139,7 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + $fileContent=$this->AddAddressTwodots($fileContent); write_file($filePath . ".html", $fileContent); } } @@ -104,12 +159,14 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + $fileContent=$this->AddAddressTwodots($fileContent); write_file($filePath . $pageNo . ".html", $fileContent); if ($pageNo == 1) { $filePath = GB_SITE_DIR . "/tags/".urlencode($tagId); if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + $fileContent=$this->AddAddressTwodots($fileContent); write_file($filePath . ".html", $fileContent); } } @@ -129,12 +186,14 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + $fileContent=$this->AddAddressTwodots($fileContent); write_file($filePath . $pageNo . ".html", $fileContent); if ($pageNo == 1) { $filePath = GB_SITE_DIR . "/archive/$yearMonthId"; if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } + $fileContent=$this->AddAddressTwodots($fileContent); write_file($filePath . ".html", $fileContent); } } @@ -156,6 +215,7 @@ public function exportSite() } $fileContent = $this->blog($blogId); + $fileContent=$this->AddAddressTwodots($fileContent); write_file(GB_SITE_DIR . '/' . $siteURL, $fileContent); } echo "export detail page success\n"; @@ -212,6 +272,10 @@ public function exportSite() echo "\nexport site success!!!\n"; } + + + + //首页 public function index() { From 495af7c404fd5bb9ba9abb8e3732dd9f28b33cfa Mon Sep 17 00:00:00 2001 From: sagaii Date: Tue, 16 Jan 2018 23:49:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A4=84=E7=90=86blog=E4=B8=8B=E5=AD=90?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=93=BE=E6=8E=A5=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/Gitblog.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/controllers/Gitblog.php b/app/controllers/Gitblog.php index 4daf847..15cd998 100644 --- a/app/controllers/Gitblog.php +++ b/app/controllers/Gitblog.php @@ -55,22 +55,26 @@ private function removeAddressFirstSlash($fileContent){ } - private function AddAddressTwodots($fileContent){ + private function AddAddressTwodots($filePath,$fileContent){ $htmlContent=$fileContent; + $htmlPath=preg_replace( '/\.\/_site\/blog\//is','../',$filePath); + + //echo "path=".$htmlPath."\n"; + //处理 //开头的 href $htmlContent= preg_replace( '/href\s*=\s*\"\/\/|\'\/\//is','href="http://',$htmlContent); //处理href - $htmlContent= preg_replace( '/href\s*=\s*\"\/|\'\//is','href="../',$htmlContent); + $htmlContent= preg_replace( '/href\s*=\s*\"\/|\'\//is','href="'.$htmlPath,$htmlContent); //处理 //开头的 src $htmlContent= preg_replace( '/src\s*=\s*\"\/\/|\'\/\//is','src="http://',$htmlContent); //处理src - $htmlContent= preg_replace( '/src\s*=\s*\"\/|\'\//is','src="../',$htmlContent); + $htmlContent= preg_replace( '/src\s*=\s*\"\/|\'\//is','src="'.$htmlPath,$htmlContent); $fileContent=$htmlContent; @@ -139,7 +143,7 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($fileContent); + $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file($filePath . ".html", $fileContent); } } @@ -159,14 +163,14 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($fileContent); + $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file($filePath . $pageNo . ".html", $fileContent); if ($pageNo == 1) { $filePath = GB_SITE_DIR . "/tags/".urlencode($tagId); if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($fileContent); + $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file($filePath . ".html", $fileContent); } } @@ -186,14 +190,14 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($fileContent); + $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file($filePath . $pageNo . ".html", $fileContent); if ($pageNo == 1) { $filePath = GB_SITE_DIR . "/archive/$yearMonthId"; if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($fileContent); + $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file($filePath . ".html", $fileContent); } } @@ -213,9 +217,9 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - + $fileContent = $this->blog($blogId); - $fileContent=$this->AddAddressTwodots($fileContent); + $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file(GB_SITE_DIR . '/' . $siteURL, $fileContent); } echo "export detail page success\n"; From bae5c64c73d388c3080a8b1e0a1cd237f0bb4b79 Mon Sep 17 00:00:00 2001 From: jenkins Date: Fri, 19 Jan 2018 23:13:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9expertSite=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E7=AB=99=E7=82=B9=E5=9C=A8blog,archive,category=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E8=BF=9E=E6=8E=A5=E4=B8=8D=E6=96=AD=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/Gitblog.php | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/app/controllers/Gitblog.php b/app/controllers/Gitblog.php index 15cd998..1f6987e 100644 --- a/app/controllers/Gitblog.php +++ b/app/controllers/Gitblog.php @@ -55,13 +55,18 @@ private function removeAddressFirstSlash($fileContent){ } - private function AddAddressTwodots($filePath,$fileContent){ + private function AddAddressTwodots($filePath,$fileContent){ $htmlContent=$fileContent; - - $htmlPath=preg_replace( '/\.\/_site\/blog\//is','../',$filePath); - - //echo "path=".$htmlPath."\n"; + + $htmlPath=$filePath; + + $htmlPath=preg_replace( '/\.\/_site\//is','', $htmlPath); + $htmlPath=preg_replace( '/([^\/]*)/is','.',$htmlPath); + $htmlPath=substr($htmlPath,0,strlen($htmlPath)-1); + if(substr($htmlPath,strlen($htmlPath)-1,1)==".") $htmlPath=substr($htmlPath,0,strlen($htmlPath)-1); + + echo "path=".$filePath."|".$htmlPath."\n"; //处理 //开头的 href $htmlContent= preg_replace( '/href\s*=\s*\"\/\/|\'\/\//is','href="http://',$htmlContent); @@ -81,7 +86,18 @@ private function AddAddressTwodots($filePath,$fileContent){ return $fileContent; } + + //修改 ../../../ 为 ../ + private function ModifyAddressThreeSlash2One($fileContent){ + + $htmlContent=$fileContent; + //处理 + $htmlContent= preg_replace( '/\.\.\/\.\.\/\.\.\//is','../',$htmlContent); + + $fileContent=$htmlContent; + return $fileContent; + } //导出网站 @@ -133,6 +149,7 @@ public function exportSite() for ($pageNo = 1; $pageNo <= $pages; $pageNo++) { $fileContent = $this->category($categoryId, $pageNo); + //$filePath = GB_SITE_DIR . "/category/".urlencode($categoryId)."/page/"; $filePath = GB_SITE_DIR . "/category/".urlencode($categoryId)."/page/"; if (!file_exists($filePath)) { mkdir($filePath, 0755, true); @@ -143,7 +160,7 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($filePath,$fileContent); + $fileContent=$this->ModifyAddressThreeSlash2One($fileContent); write_file($filePath . ".html", $fileContent); } } @@ -166,11 +183,11 @@ public function exportSite() $fileContent=$this->AddAddressTwodots($filePath,$fileContent); write_file($filePath . $pageNo . ".html", $fileContent); if ($pageNo == 1) { - $filePath = GB_SITE_DIR . "/tags/".urlencode($tagId); + $filePath = GB_SITE_DIR . "/tags/".urlencode($tagId); if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($filePath,$fileContent); + $fileContent=$this->ModifyAddressThreeSlash2One($fileContent); write_file($filePath . ".html", $fileContent); } } @@ -197,7 +214,7 @@ public function exportSite() if (!file_exists($filePath)) { mkdir($filePath, 0755, true); } - $fileContent=$this->AddAddressTwodots($filePath,$fileContent); + $fileContent=$this->ModifyAddressThreeSlash2One($fileContent); write_file($filePath . ".html", $fileContent); } } @@ -269,6 +286,8 @@ public function exportSite() $feedXmlfilePath = GB_SITE_DIR . "/feed.xml"; $feedXmlfileContent = $this->feed(); write_file($feedXmlfilePath, $feedXmlfileContent); + + if(file_exists($serverPath."CNAME")) copy($serverPath."CNAME", GB_SITE_DIR . "/CNAME"); copy("robots.txt", GB_SITE_DIR . "/robots.txt"); copy("favicon.ico", GB_SITE_DIR . "/favicon.ico");