2017年8月30日 星期三

Git的世界 - 安裝跟基本操作

非常常聽到,聽起來就很厲害的東西,Git,我現在處於一知半解,還未能融入工作模式的情況下,開始這個學習紀錄:

外部資源:
Git 教學(1) : Git 的基本使用
使用 Git 做為網站開發版本控管工具

第一部分:環境
1. 註冊Github帳號
2. 安裝Git環境
   Download and install the latest version of Git.
   Set your username in Git.
   Set your commit email address in Git.
3. Git是可以用command line全程操作,若需要有GUI的軟體可以用
4. command line的操作稍微熟悉一下
5. 複習vim文字編輯器(最下面)

第二部分:基本操作
1. init (開啟一個自己的Repository, 專案工作區)
在cmd中 cd 進入欲工作的資料夾,指令 git init,就會將這個資料夾開成Repository

2. clone (複製別人在網路上的專案)

指令:git clone "要clone的專案網址"
整個專案就會下載到local資料夾中

3. Repository的狀態:Status, Add, Commit, log, .gitignore

$ git status : 確認目前專案裝態
$ git add "filename" : 新增/改過的檔案原本是untracked的狀態,add 可以把檔案轉成"stage"狀態,在下次更新時就會上傳。沒有經過 add 的是"unstage"狀態

git add test.php 之後:

$ git commit
會把更新的檔案上傳,一個commit就是一個節點,作為未來可以追蹤或回溯的參考。未來若有需要可以回到這個存檔狀態。
git commit之後會看到下列內容:

或是用 git commit -m "commit message" 比較快,盡量寫清楚,讓未來自己與別人都好懂。

$ git log
可以看到過去commit的紀錄


git log --stat 可以看到更完整的commit紀錄
git log -p      可以看到更完整的檔案修改內容

$ vim .gitignore 會進入一個文字檔,讓不想加入版本控制的檔案標記起來,以後就不會一直更新了。


vim文字編輯器的基本操作(更多看這裡):
1. 按 i ,進入編輯
2. 編輯文字
3. 按esc,然後按":"
4. 接下來檔案編輯完的處理:可以按 q (離開) / w(寫入)/ qw(寫入後離開)



2017年8月29日 星期二

如何在Wordpress網頁中內嵌臉書相片/相簿


無論個人或公司,可能有網站又有臉書專頁,若想要省去上傳兩次照片的作業,只上傳一次到臉書,就能同時也讓網頁顯示最新內容,瀏覽相簿,要如何做呢?
這是demo網頁,還有lightbox的切換效果。

我一開始先搜尋了這個:在WP網頁嵌入臉書的相簿(可在網頁上直接瀏覽臉書相片),介紹了其中一種外掛,之後還試了幾種WP外掛,如以下:

1. Facebook Feed WD: 可以抓動態貼文到網頁,但預設全類型,若要指定圖片或其他就要購買。如果專門用手機瀏覽還算方便。(我的自製theme點開lightbox會有錯誤)




2. WP Embed Facebook:
有縮圖,有lightbox,但是縮圖太小不能調整,蠻可惜,如果這外掛的規劃範圍不大可以考慮。

3. Custom Facebook Feed Pro
介面設計得不錯但客製化功能要用買的

4. Feed them social
跟3一樣,若要客製化layout或是點開相片的lightbox就要購買。純粹貼文的顯示在手機上瀏覽還不錯。

試完上面幾個外掛,我覺得若不付費用,功能都閹割得太多,很不理想。這些外掛主要是給無法自己開發或使用開源框架的人付費使用,我也希望能夠多有一點自己開發的自由。


一直尋找線上資源,最後找到這個網站 www.codeofaninja.com 有步驟教學,比較適合開發者。他們有賣外掛,但也有把code內容放上來做成教學,真是少見不藏私的風格。

follow完上面的教學,以下是我一步步coding到WP的步驟:


一、這是一段完整的內嵌php網頁code,用顏色區分要切給Wordpress的區塊
-----code-----
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

    <!-- blue imp gallery -->
    <link rel="stylesheet" href="http://blueimp.github.io/Gallery/css/blueimp-gallery.min.css">
    <link rel="stylesheet" href="Bootstrap-Image-Gallery-3.1.1/css/bootstrap-image-gallery.min.css">

    <style>
    .photo-thumb{
        width:150px;
        height:150px;
        float:left;
        border: thin solid #d1d1d1;
        margin:0 1em 1em 0;
    }

    div#blueimp-gallery div.modal {
        overflow: visible;
    }

    #wrapper {
    text-align: center;
    }

    #gal-img {
      display: inline-block;
    }
    </style>
</head>
<body>

<div class="container">
<?php
 
$access_token="你的FB access token";
$album_id="你的FB相簿id";
$json_link = "https://graph.facebook.com/v2.3/{$album_id}/photos?fields=source,images,name&access_token={$access_token}";
$json = file_get_contents($json_link);
 
$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
 
$photo_count = count($obj['data']);

echo "<div id='wrapper'>";
for($x=0; $x<$photo_count; $x++){
 
   $source = isset($obj['data'][$x]['images'][0]['source']) ? $obj['data'][$x]['images'][0]['source'] : ""; //hd image
   $name = isset($obj['data'][$x]['name']) ? $obj['data'][$x]['name'] : "";
 
   echo "<a id='gal-img' href='{$source}' data-gallery>";
       echo "<div class='photo-thumb' style='background: url({$source}) 50% 50% no-repeat;background-size: cover; overflow:auto;'>";
 
       echo "</div>";
   echo "</a>";
 
}
echo "</div>";
?>
</div>

<!-- The Bootstrap Image Gallery lightbox, should be a child element of the document body -->
<div id="blueimp-gallery" class="blueimp-gallery">
    <!-- The container for the modal slides -->
    <div class="slides"></div>
    <!-- Controls for the borderless lightbox -->
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
    <!-- The modal dialog, which will be used to wrap the lightbox content -->
    <div class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" aria-hidden="true">&times;</button>
                    <h4 class="modal-title"></h4>
                </div>
                <div class="modal-body next"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left prev">
                        <i class="glyphicon glyphicon-chevron-left"></i>
                        Previous
                    </button>
                    <button type="button" class="btn btn-primary next">
                        Next
                        <i class="glyphicon glyphicon-chevron-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<script src="http://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
<script src="Bootstrap-Image-Gallery-3.1.1/js/bootstrap-image-gallery.min.js"></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- to make photos full view -->
<script>
$('#blueimp-gallery').data('useBootstrapModal', false);
$('#blueimp-gallery').toggleClass('blueimp-gallery-controls', true);
</script>

</body>
</html>
-----code ended-----

二、我們要把上面的code整理到Wordpress:
1. 上面header中紫色的css reference整併到WP theme的footer.php
2. 上面footer中紫色的js reference整併到WP theme的footer.php
3. 上面橘色的css reference貼到WP theme裡面的.css檔
4. 上面所有紅色的php code部分用WP外掛"Insert PHP Code Snippet"做一個shortcut,記得放在一起,變數才讀得到。
(注意!<blueimp-gallery>這個放進外掛的html div要先轉成php code,不然網頁會失敗):
------code------
$access_token="your access token";
$json_link = "https://graph.facebook.com/v2.3/"your album id"/photos?fields=source,images,name&access_token={$access_token}";
$json = file_get_contents($json_link);

$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

$photo_count = count($obj['data']);

echo "<div id='wrapper' style='margin-top:20px;'>";
for($x=0; $x<$photo_count; $x++){

   $source = isset($obj['data'][$x]['images'][0]['source']) ? $obj['data'][$x]['images'][0]['source'] : ""; //hd image
   $name = isset($obj['data'][$x]['name']) ? $obj['data'][$x]['name'] : "";

   echo "<a id='vul-img' href='{$source}' data-gallery>";
       echo "<div class='photo-thumb' style='background: url({$source}) 50% 50% no-repeat;background-size: cover; overflow:auto;'>";

       echo "</div>";
   echo "</a>";

}
echo "</div>";

echo "<div id=\"blueimp-gallery\" class=\"blueimp-gallery\">\n";
echo "    <!-- The container for the modal slides -->\n";
echo "    <div class=\"slides\"></div>\n";
echo "    <!-- Controls for the borderless lightbox -->\n";
echo "    <h3 class=\"title\"></h3>\n";
echo "    <a class=\"prev\">‹</a>\n";
echo "    <a class=\"next\">›</a>\n";
echo "    <a class=\"close\">×</a>\n";
echo "    <a class=\"play-pause\"></a>\n";
echo "    <ol class=\"indicator\"></ol>\n";
echo "    <!-- The modal dialog, which will be used to wrap the lightbox content -->\n";
echo "    <div class=\"modal fade\">\n";
echo "        <div class=\"modal-dialog\">\n";
echo "            <div class=\"modal-content\">\n";
echo "                <div class=\"modal-header\">\n";
echo "                    <button type=\"button\" class=\"close\" aria-hidden=\"true\">&times;</button>\n";
echo "                    <h4 class=\"modal-title\"></h4>\n";
echo "                </div>\n";
echo "                <div class=\"modal-body next\"></div>\n";
echo "                <div class=\"modal-footer\">\n";
echo "                    <button type=\"button\" class=\"btn btn-default pull-left prev\">\n";
echo "                        <i class=\"glyphicon glyphicon-chevron-left\"></i>\n";
echo "                        Previous\n";
echo "                    </button>\n";
echo "                    <button type=\"button\" class=\"btn btn-primary next\">\n";
echo "                        Next\n";
echo "                        <i class=\"glyphicon glyphicon-chevron-right\"></i>\n";
echo "                    </button>\n";
echo "                </div>\n";
echo "            </div>\n";
echo "        </div>\n";
echo "    </div>\n";
echo "</div>\n";

echo "<script>";
echo "$('#blueimp-gallery').data('useBootstrapModal', false);";
echo "$('#blueimp-gallery').toggleClass('blueimp-gallery-controls', true);";
echo "</script>";
-----code ended-----

下一步,開新的page,
把上面背景黃色的code,就是以下這段貼上,就完成了!
-----code-----
<div class="container">
[xyz-ips snippet="你取的外掛變數名稱"]
</div>
-----code ended-----

如果都跟著做完,看看效果吧 demo

謝謝寫教學的codeofaninja.com,也希望你成功。



附註連結:
如何開啟一個臉書App,並且得到授權key,以用來來取得臉書資源到外部

如何取得臉書access id

如何取得臉書page id




2017.Aug

如何移除WP編輯內容時自動多出來的空白元素

2016年7月17日 星期日

HTML - Note3: CSS(2)

CSS可以做到以下:

*改變字體、顏色、大小
h1 {
  font-size: 32px;
  font-family: Palatino, 'Palatino Linotype', serif;
  color: #2e69a3;
}

*新增/ 調整背景圖
background-image: url("https://s3.amazonaws.com/codecademy-content/projects/make-a-website/lesson-2/bg.jpg");

*改變整個class的風格(字體顏色大小)
index.html裡面:
  <div class="hero">
        <h2>Sprout.</h2>
        <p>A book by J. Daniel Bedford</p>
        <a href="#">Read now.</a>
  </div>

css裡面:
.hero {
  padding: 250px 0;
  margin: 30px;
  background-size: cover;
  color: #ffffff;
}


*以#跟賦予id的方式來改變特定元素的風格,而其他同類的不變
(在index.html裡面)  <p id="footer">&copy; Mystwood Publishers Limited</p>
(在CSS裡面)#footer { font-size: 0.75rem; color: red; }



HTML - Note2: CSS


CSS是一種方便的語法,來組織網頁元素的風格,我用Codecademy的截圖來說明它的能力:

左邊是HTML檔,先把CSS的呼叫註解起來的樣子



呼叫了CSS描述檔之後,效果如下圖:

在main.css檔中,可以看到各種的元素風格定義方式:





































所以把視覺風格跟網頁內容配置,分開來定義,就是這樣的感覺。


HTML - Note1

我個人感覺,一個以視覺主導思維的設計師或藝術家,在訓練過程已很習慣拿熟悉的元素作拼貼;
而在學習HTML時,這些拼貼的元素會變成一行行程式碼,經過練習後,設計網站就像在拼貼這些程式碼;到了CSS的時候,會把“拼貼”跟“設計”這兩項工作分開,過程上更有效率,上手的人會用「強大」來形容它的能力,但這也是從“物理世界”轉換到“工程思維”的階段,對藝術家是個大挑戰。


Div element:

Div elements divide your page by enclosing other elements. These enclosed groups of elements can then be organized, moved and styled independently from one another.

<div class="main"> ...</div>

它是用來分割網頁元素,以群組方式歸類,要調整位置與風格時,就一次處理整個Div


Metadata processes:
像是網頁的腦袋,因為它們溝通、傳遞訊息,但是使用者看不到。
<!DOCTYPE html> // Tells the web browser to expect an HTML document.
<html>...</html> // The root of the HTML document and parent of all other HTML elements on the webpage.
<head>...</head> // Enclose other metadata about the site, such as its title.
<title>...</title> // Contains the site's title, which is one way users can find your site through a search engine, like Google.
<meta charset="utf-8”/> // Tells the web browser which character set to use. In this case, the character set is "utf-8".

CSS:
stands for cascading style sheets, and is used to style HTML elements. 用層疊的概念做網頁元素的風格設計。

HTML elements:
* h1-h6: <h1>Heading</h1>  數字越小,字越大,通常用在標頭
* p: <p>Description of company here.</p>在標頭以外,文章或描述片段的時候使用
* a: <a href="http://codecademy.com">Click here</a> to learn how to make a website! a是Anchor(錨)的縮寫,用在外部網頁連結上
* img: <img src="https://images.com/favorite.png> 使用圖片元素
* video: 影片
* unordered list:
<ul>
<li>list item</li>
<li>another item</li>
<li>yet another</li>
</ul> // 未排序的清單
* div: 拿來整理所有HTML元素並且使用class的屬性,並且需取名字
<div class="main">
<h2>Subheading!</h2>

</div>

2016年7月12日 星期二

RaspBerry Pi 3 - Note 1 初始設定紀錄

<RaspBerry Pi 3的撞牆記>

我犯了幾個錯:
1. 插上記憶卡就接上電源螢幕沒反應,以為電流不夠大
2. 記憶卡也沒完全格式化就裝OS,沒有反應
3. 用Mac的terminal裝OS,看不到進度條,一個多小時過後直接拔
4. 用5V 1.2A電源,不夠力
5. 再用Windows重裝幾次,拔插幾次,SD就GG了

這邊整理一下正確的方式:
0. 下載好OS的映像檔 (樹莓派官網上Download頁的NOOBS或RASPBIAN, 解壓)
1. 器材準備好(Pi 3, 螢幕+HDMI線, 網路線, Micro USB 5V 2A變壓器跟線都要夠力, Micro SD & 讀卡機, 無線鍵鼠K270+M185)
2. 必要!下載免費軟體 SD Formatter,把SD卡清除乾淨
3. 下載免費軟體 Win32 Disk Manager,SD卡>讀卡機>電腦,它會抓SD來源,然後選OS映像檔來源,點選"write"寫入
4. 跑完後安全退出SD卡,插進RB Pi3,確認HDMI線、網路線、無線鍵鼠接好
5. 接上Micro USB電源,就會自動開機了,RB Pi3沒有電源鍵

這樣就可以真正開始玩樹莓派了,呼~

然後上面的東西我花了一天才搞定@_@|||



設定用VNC遠端控制的方式,參照趙老師的這篇:

參考這個設定開機即開啟VNC


蠻方便的,除了開機即開之外,還試了用Android手機遠端控制,很方便!



2016年7月11日 星期一

AngularJS - Note1 & 近況

這裡有一陣子沒有更新了,後來我把教學書上兩個遊戲(圍住貓 & 橫向卷軸移動跳躍)跟著書實作完。而五月初時我體驗到了VR(HTC Vive)很受感動,決定投入開發,加上一些機緣接觸到IOT的起點,就開始玩Arduino,這些過程我PO在另一個與友人的共同blog,內容比較多圖像、視覺跟實體互動,連結如下:

JB-Dummies:
https://jbdummies.wordpress.com/


然後我現在除了Maker的東西 (七月底要去上海參加Maker活動),同時也在自學AngularJS和HTML、JavaScript,Codecademy上面學習的流程設計真的很不錯,繼續GO~



AngularJS - Note1

AngularJS是一種JavaScript的framework,能用來開發彈性化、好管理的網頁App,需要一點JavaScript跟Html基礎。我在Codecademy上學,目前進度到Unit 2 (2/5) 的50%。


接下來程式碼示範的網頁如下圖所示:


我把裡面有關資料的三個檔案view拼在一起,從以下兩張圖對照看,左下是Html,左上是定義資料型別的規則,右邊是資料存放的地方。把三個東西拆開,就很方便做管理。

例如說,不管我想新增幾筆資料,在右方的檔案新增就好,如果我想移動顯示的位置,

修改左下方檔案的code就好。

“Directive是AngularJS中一個很像自訂標籤的東西,有很客製化的彈性可以設定要讀取的資料型態”
以上是我目前的理解,還在跟著段落code一點一點感受中... ^_^|||

在Directive裡面的7/8,我開始靈魂游離,覺得應該要再多看一點HTML的東西,這個章節結束後就開始吧= =

走完8/8,下面有個Directive的總結:
  • Directives are a powerful way to create self-contained, interactive components. Unlike jQuery which adds interactivity as a layer on top of HTML, AngularJS treats interactivity as a native component of HTML.

讓我們繼續 走下去。