<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 許展源 on Medium]]></title>
        <description><![CDATA[Stories by 許展源 on Medium]]></description>
        <link>https://medium.com/@jyhsu2000?source=rss-1d99f6d6369e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7vdlDY2nzt3xN75PgOiRMA.jpeg</url>
            <title>Stories by 許展源 on Medium</title>
            <link>https://medium.com/@jyhsu2000?source=rss-1d99f6d6369e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:57:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jyhsu2000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[【開發筆記】黑客社 3.0]]></title>
            <link>https://medium.com/@jyhsu2000/%E9%96%8B%E7%99%BC%E7%AD%86%E8%A8%98-%E9%BB%91%E5%AE%A2%E7%A4%BE-3-0-421eca37df2?source=rss-1d99f6d6369e------2</link>
            <guid isPermaLink="false">https://medium.com/p/421eca37df2</guid>
            <dc:creator><![CDATA[許展源]]></dc:creator>
            <pubDate>Thu, 11 Oct 2018 08:36:15 GMT</pubDate>
            <atom:updated>2018-10-25T06:02:48.488Z</atom:updated>
            <content:encoded><![CDATA[<p>一切，要從<a href="https://hackersir.org/">黑客社網站</a>說起……<br>在某活動結束的深夜，<br>幾位社團元老聚在一起討論，（好像連我和火文狼在內總共也只有兩位QwQ）<br>想說社網太久沒更新，需要更新一下<br>對社團網站做出了幾個決定：</p><ul><li>應該將網站移出 <a href="https://github.com/HackerSir/HackerSir.github.io">HackerSir.github.io</a> 專案，<br>每年的網站獨立開設 Repo，<br>再以 Git Submodule 的形式加入主要網站專案，<br>並以年份作為資料夾名稱，區分每年的網站</li><li>開始著手開發 2018 版本的網站，<br>以 <a href="https://vuejs.org/">Vue.js</a> 為核心，<br>搭配 <a href="https://router.vuejs.org/">vue-router</a> 建立 SPA（單頁應用，Single-Page Application）</li><li>整理並重新收錄歷屆資料</li><li>內容架構參考舊網站，並重新調整</li></ul><h3>2018–05–02 午夜</h3><p>直接開始動工<br>先從內容架構開始討論，包含頁面的架構以及各類資料如何儲存於JSON檔案<br>原以為到天亮之前，可以弄出個雛形，<br>但這工程遠比想像中的大，<br>光是討論完這些部分，就天亮了……</p><h3>2018–05–03 晚上</h3><p>為了這次的SPA需求，<br>開始學習 <a href="https://vuejs.org/">Vue.js</a> 和 <a href="https://github.com/vuejs/vue-cli">vue-cli</a>、<a href="https://router.vuejs.org/">vue-router</a> 等套件<br>雖然過去多年累積的網站開發經驗中，多少也有接觸 Vue.js，但重點大多在於 Laravel 本身，鮮少接觸 Vue.js 真正精采的部分<br>這次也算是個特別的機會吧</p><p>之前為了在 Laravel 的網站專案中，利用 Vue.js 製作一些功能，曾徹底讀過 <a href="https://vuejs.org/v2/guide/">Vue.js 的文件</a>，<br>因此這次一開始即是將重點擺在 vue-cli 和 vue-router 兩個較陌生的部分</p><p>初接觸時，教材的選擇會影響到後面的發展，<br>我選擇了 <a href="https://dotblogs.com.tw/wasichris/series/1?qq=Vue">[Vue] 跟著 Vue 闖盪前端世界</a>，<br>算是非常好理解的文章，照順序看過之後，就能初步了解這些部分</p><p>但是，狀況發生了……<br>執行「npm i -g vue-cli」安裝 vue-cli 之後，找不到 vue 指令<br>發現似乎是 Windows 版的 Node.js 安裝限制<br>手動將「C:\Users\使用者名稱\AppData\Roaming\npm」加入 Path 之後解決了問題</p><p>利用互動式指令「vue init 樣板名稱 專案名稱」建立了第一個測試專案</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*6tQ4LbO-VirexZfe_BCFxQ.png" /><figcaption>建立專案</figcaption></figure><p>接著進入資料夾，依序執行「npm i」、「npm run dev」<br>即會自動啟動伺服器於 <a href="http://localhost:8080/">http://localhost:8080</a><br>如此便能看到專案運行的樣子囉！</p><p>簡單寫了幾個元件，測試 vue-router 的運作方式<br>新增元件的方式：</p><ol><li>在 src/components 建立 <strong>元件名稱.vue</strong> 檔案</li><li>修改 src/router/index.js 將元件加入其中，<br>利用「import 元件名稱 from ‘@/components/元件名稱’」匯入元件，<br>並在 routes 區段定義 path、name、component</li></ol><p>接著試著在 routes 的既有路由上新增子路由，<br>方法雷同，但不是放在 routes 那層，而是在既有路由的定義放上 children 陣列，再將定義放於其中</p><p>在嘗試路由參數時，則遇到較多問題<br>例如 props 抓不到路由參數，才發現路由參數與屬性不同，是定義於 data 中，並指定預設值為「this.$route.params.參數名稱」<br>這部分只是說明沒看清楚導致，頗輕易就解決了</p><p>但後來遇到的，就是比較麻煩的了<br>了解到使用 &lt;router-view&gt;&lt;/router-view&gt;定義元件顯示區塊、使用&lt;router-link :to=”{path: “/路由”}”&gt;&lt;/router-link&gt; 定義超連結<br>但卻發現，某些超連結被點擊之後，顯示上並不會重新渲染，導致資料更新無法顯示於介面上</p><p>很慶幸的，一下子就找到相關文章<br><a href="https://laracasts.com/discuss/channels/vue/vue-2-reload-component-when-same-route-is-requested">[Vue 2] Reload component when same route is requested</a><br>得知只需要將 router-view 改寫為以下形式，即可解決</p><pre>&lt;<strong>router-view</strong> :key=&quot;$route.fullPath&quot;&gt;&lt;/<strong>router-view</strong>&gt;</pre><p>這是因為 vue-router 並沒有注意到相同路由僅有參數不同時的頁面改變，這項設定能迫使其發現這改變，並重新顯示於畫面上</p><p>大致上對於這次網站的開發有了方向</p><h3>2018–05–04</h3><p>準備開始動工專案，<br>想說先弄個 Layout，<br>再去分頁面類型，<br>卻發現……<br>Vue 的 template 使用 HTML 的話，<br>似乎沒有 extend 的概念可以做繼承</p><p>上網試著找了些資料，<br>看到 <a href="https://medium.com/js-dojo/extending-vuejs-components-42fefefc688b">Extending VueJS Components</a> 這篇文章提到<br>可以使用 <a href="https://pugjs.org/">Pug</a> 取代 HTML 作為樣板語言，<br>如此便能使用 Pug 的 <a href="https://pugjs.org/language/inheritance.html">Template Inheritance</a> 實現 extend</p><p>把 P<a href="https://pugjs.org/">ug 的文件</a>大致看過後，<br>直接實際建立專案：<br><a href="https://github.com/HackerSir/hackersir-web-2018">https://github.com/HackerSir/hackersir-web-2018</a><br>照著 <a href="https://dotblogs.com.tw/wasichris/2017/03/01/172049">[Vue] 跟著 Vue 闖蕩前端世界 — 02 使用 Vue-cli 建構專案</a> 的說明將專案建構起來，<br>差別只在於 npm 相關指令，被我替換成更高效率的 <a href="https://yarnpkg.com/">Yarn</a>，<br>並順便安裝了 Pug，<br>接著邊學邊嘗試，<br>順利將各頁面的檔案和設定搞定</p><p>過程中<br>討論到靜態資源的發佈，<br>嘗試後才發現<br>資料夾 static 中的檔案，會照原樣直接發佈到路徑 /static/ 中</p><h3>2018–05–06</h3><p>挑選 CSS 框架的重要時刻到了，<br>Danny 直接選擇 Bootstrap，火文狼直接表示處於弱勢XD<br>（火文狼慣用 Semantic UI，其他人則偏好 Bootstrap）<br>於是後來決定…… Material Design ヾ(@°▽°@)ノ<br>不……應該說是，披著 Material Design 外皮的 Bootstrap<br>姑且從眾多類似的 CSS 框架中選擇了 <a href="https://fezvrasta.github.io/bootstrap-material-design/">Material Design for Bootstrap</a></p><p>設定圖片背景時，<br>被靜態資源的取用方式困擾了一下，<br>在&lt;style&gt;&lt;/style&gt;區段，為 body 指定背景，<br>但路徑怎麼寫都出現</p><pre>This relative module was not found</pre><p>爬了些文章後<br>找到一則 Issue<br><a href="https://github.com/vuejs/vue-loader/issues/193">html image src require not respecting webpack aliases?</a> <br>發現路徑要加上「~@」才能正確識別，於是變成</p><pre>&lt;style&gt;<br>  body {<br>    background: url(https://medium.com/~@/assets/index-background.jpg);<br>  }<br>&lt;/style&gt;</pre><p>圖片總算是能正確出現了，<br>不過遇到更麻煩的問題，<br>style 去指定 body 背景的話，換頁不會自動失效，<br>但如果用 style scoped，又無法將風格指定到該 vue 檔以外的標籤<br>（body 是在作為基礎樣板的 index.html 中）<br>只好暫時將背景移到 index.html 作為全域設定，圖片也移回 static/image 作為靜態檔案直接存取</p><p>經過一整晚的努力，<br>將大致頁面架構搞定了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEepzGZr3Y3P0SDph2ZRtA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yDqmvZ6XxgERLM0ucw_hhg.png" /><figcaption>首頁（左）與一般頁面（右）</figcaption></figure><h3>2018–05–07</h3><p>意外發現<br>直接訪問未定義的路由時，會出現空白頁面（就是 App.vue，但 router-view 沒東西的情況）<br>如果是在頁面中，切換到未定義路由，則頁面會保持前一個狀態，不會有任何改變<br>這點與平常認知的不太一樣</p><p>查了些資料後得知<br>若需要 404 頁面，需要自行在 router 定義的最後面加上 path 為 * 的方案，匹配所有前面沒匹配到的狀況</p><pre>{<br>  path: &#39;*&#39;,<br>  name: &#39;PageNotFound&#39;,<br>  component: PageNotFound<br>}</pre><p>準備為 SEO 進行修改時<br>也面臨了一些問題<br>favicon 無法放置於根目錄，只能放在 static，需要用 link 標籤去指定<br>比較麻煩的是，og:image、twitter:image:src需要指定絕對路徑<br>但之後佈署後，可能會是在主機根路徑，或是 hackersir.org/2018<br>暫時無法處理，只好使用 HackerSir.github.io 專案的圖片 //hackersir.org/img/logo-256.png</p><p>尋找工具方便讓大家將專案佈署到 GitHub Pages<br>找到了 <a href="https://github.com/jeneser/vue-cli-ghpages">vue-cli-ghpages</a><br>但這款是要全域安裝，在使用其 vcg 指令<br>考慮之後，直接包到專案中，並建立 yarn run deploy 指令<br>利用其執行建置動作，並呼叫 vcg 指令將 dict 資料夾佈署到 gh-pages 分支</p><pre>&quot;scripts&quot;: {<br>  (...),<br>  &quot;deploy&quot;: &quot;npm run build &amp;&amp; vcg --message=\&quot;Deploy to gh-pages\&quot;&quot;<br>},</pre><p>唯一比較需要注意的是<br>由於在 GitHub Pages 佈署，並非是網站根路徑<br>config/index.js 中，build 區段的 assetsPublicPath 需額外修改為 ./</p><pre>assetsPublicPath: &#39;./&#39;,</pre><p>以確保佈署出來的專案能在非根路徑下順利執行</p><p>深夜發現 footer 在手機會吃到內容<br>果斷將 footer 改為使用 flex 定義位置</p><h3>2018–05–08</h3><p>開始研究 JSON 載入機制<br>選擇使用 <a href="https://github.com/axios/axios">axios</a></p><p>使用上有兩種方案<br>Global：直接在 main.js 加上</p><pre>window.axios = require(&#39;axios&#39;)<br>window.axios.defaults.headers.common[&#39;X-Requested-With&#39;] = &#39;XMLHttpRequest&#39;<br>Vue.prototype.$http = window.axios</pre><p>呼叫時，使用 this.$http.get（與 <a href="https://github.com/pagekit/vue-resource">vue-resource</a> 相容）或 window.axios.get</p><p>Local：在需要的地方加上</p><pre>import axios from &#39;axios&#39;</pre><p>呼叫時，則直接使用 axios.get</p><p>由於這專案有不少地方會用到<br>最後決定採用 this.$http.get</p><p>在撰寫社團規章頁面時，<br>打算直接透過 Ajax 拿 <a href="https://github.com/HackerSir/Articles-of-association">Articles-of-association</a> 專案的 <a href="https://github.com/HackerSir/Articles-of-association/blob/master/rules.md">rules.md</a><br>但 GitHub 不允許原始檔被 Ajax 載入<br>於是決定利用 <a href="https://rawgit.com/">RawGit</a> 作為 CDN 協助載入<br>但缺點是檔案必須指定 commit 編號，未來修改社規可能會需要一併修改此處</p><p>後來發現，其實 GitHub API 可以方便直接取得最新的 commit id<br><a href="https://developer.github.com/v3/repos/commits/">https://developer.github.com/v3/repos/commits/</a><br>於是先<a href="https://api.github.com/repos/HackerSir/Articles-of-association/commits/master">呼叫 API 取得 commit id</a><br>再將該 commit id 拼湊出 RawGit 需要的網址，即可確保不受 RawGit 緩存影響，隨時取得最新版</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fuf8p7zZxaF4XOOEQ-kgHw.png" /></figure><p>為這專案加上 <a href="https://fontawesome.com/">FontAwesome</a> 的 Pro 版 CDN 時，<br>發現原來我的 License 可以綁定 30 組域名</p><h3>2018-05-09</h3><p>心血來潮逛了下 <a href="https://github.com/vuejs/awesome-vue">Awesome Vue.js</a><br>發現有頗好用的 Markdown 套件 <a href="https://github.com/miaolz123/vue-markdown">vue-markdown</a><br>於是就……果斷換掉XD</p><p>差別在於不用自己建立 converter 去做轉換動作<br>而是有現成的 VueMarkdown 這個 component<br>使用上也頗容易，直接用 source 指定變數即可</p><pre>&lt;vue-markdown :source=&quot;rule&quot;&gt;&lt;/vue-markdown&gt;</pre><p>在社團介紹頁面，<br>h3 的前後都有星號<br>原本直接用標籤插入 FontAwesome 的圖示<br>這次試著改用 CSS</p><pre>h3::before, h3::after {<br>  content: &quot;\f005&quot;; /* fa-star */<br>  font-family: &#39;Font Awesome 5 Pro&#39;;<br>  font-weight: 900; /* fas */<br>}</pre><p>content 可以直接從 FontAwesome 網站查詢<br>font-family 固定為 Font Awesome 5 Pro<br>而 font-weight 則是指定 Solid(900)、Regular(400)、Light(300) 三種風格的關鍵</p><h3>2018–05–12</h3><p>發現 <a href="http://framework7.io/docs/timeline.html">Framework 7 的 Timeline</a> 看起來不錯<br>覺得或許可以參考<br>簡約風覺得還不錯</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*OWpyIMF_tp1PpzlMqUi9Sg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*5s4dIWeg1r8gPWRx19MPiQ.png" /></figure><p>不過麻煩點在於<br>這是在框架中的一部份<br>需要想辦法抄出來</p><h3>2018–05–13</h3><p>試著參考前面那款 Timeline 完成了自己的版本</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cnw_ixUK1n9OsmuALvAZ-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*uDv7wra72jbEKV0vUvVApA.png" /></figure><p>在仿寫的過程中<br>發現 CSS 中有個 flex-shrink 屬性<br>這個屬性是在 flex 中控制壓縮程度使用的<br>當父容器的空間不足時，照該值的比例壓縮空間<br>0 表示不壓縮<br>用以強化響應式設計的縮放方式</p><p>這時間軸比較有巧思的部分<br>是兩個圓點之間的直線<br>利用 CSS 的 before 和 after 實現的</p><pre>.timeline-item-divider:before {<br>  bottom: 100%;<br>}<br>.timeline-item:first-child .timeline-item-divider:before {<br>  display: none;<br>}<br>.timeline-item-divider:after {<br>  top: 100%;<br>}<br>.timeline-item:last-child .timeline-item-divider:after {<br>  display: none;<br>}<br>.timeline-item-divider:after,<br>.timeline-item-divider:before {<br>  content: &quot; &quot;;<br>  width: 5px;<br>  height: 100vh;<br>  position: absolute;<br>  left: 50%;<br>  background: inherit;<br>  -webkit-transform: translate3d(-50%, 0, 0);<br>  transform: translate3d(-50%, 0, 0);<br>}</pre><h3>2018–05–14</h3><p>完成了合作夥伴頁面<br>考慮把內容移到 Vue 的 data 中<br>但對於靈活度的拿捏還需要思考一下</p><h3>2018–05–20</h3><p>試著了解 ES6 的箭頭函式，<br>得知使用<a href="https://pjchender.blogspot.tw/2017/01/es6-arrow-function.html">箭頭函式</a>的話，與一般 function 不同，<br>在定義時，「this」會自動綁定定義時的「this」，而不像匿名函式有自己的 this<br>於是試著將社團規章部分，利用 axios 呼叫 API 的回應處理部分，改以箭頭函式取代匿名函式</p><h3>2018–05–26</h3><p>覺得合作夥伴頁面，HTML內容會隨資料增加而不斷重複<br>一開始決定將資料提到 data 區段<br>後來決定乾脆直接提到獨立檔案 partner.json</p><h3>2018–06–02</h3><p>試著參考 <a href="https://github.com/acornejo/bootstrap-nav-wizard">bootstrap-nav-wizard</a> 為歷屆幹部頁面加上 Wizard<br>但各項之間的空白處似乎無法支援透明背景，介面上還很需要調整</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbVW9avf_uH5S3QCielQpA.png" /></figure><p>點擊連結時，需要整頁重新渲染<br>這點可能也需要修正<br>或許這篇有些幫助：<a href="https://github.com/vuejs/vue-router/issues/703">Allow absolute path change without destroying rendered components (Twitter-style modals)</a></p><p>資料格式目前使用屆數當 key<br>但發現以數字做為 key 的部分會自動重新排序，無法保持原有順序<br>雖然影響不大，但怕未來會影響到其他機制的實現</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*tsV_hjxUgym3Gsmcr7cQmQ.png" /></figure><h3>2018–06–04</h3><p>為了避免如歷屆幹部頁面選擇不同屆數時，造成多次重新讀取 JSON<br>姑且先將 router-view 的 :key=”$route.fullPath” 全數移除</p><p>歷屆幹部頁面的屆數切換改為對 $route.params.year 進行監看<br>唯一需要注意的地方是，mounted 時並不會觸發 watch<br>因此需要將實際動作提取到 methods，在 watch 呼叫，並於 mounted 時手動觸發一次</p><h3>2018–06–08</h3><p>在撰寫「加入我們」頁面時<br>發現以 FontAwesome Icon 作為清單的標號時<br>標號與文字之間的間隔難以調整，設定 icon 的 margin 反而會動到整個 li<br>果斷將 icon 直接移到 li::before 定義</p><pre>li::before {<br>  content: &quot;\f14a&quot;; /* fa-check-square */<br>  font-family: &#39;Font Awesome 5 Pro&#39;;<br>  font-weight: 400; /* far */<br>  margin-right: .2rem;<br>}</pre><h3>2018–10–23</h3><p>久違的再度動工<br>把歷屆幹部頁面的排版修正了<br>補上 flex-wrap，讓元件能夠自動換行</p><p>也順便把自己的資料放了上去<br>改資料時發現<br>一個人擔任多屆或多種職務時，需要重複編輯好像有點麻煩</p><h3>2018–10–24</h3><p>發現歷屆幹部頁面在手機上有嚴重問題<br>暫時用 Flex 重新排過<br>選擇幹部之後，若在較小頁面<br>以改為將幹部清單維持顯示在上側，並使其能夠橫向滾動<br>而非如較大畫面顯示於左側</p><h3>To Be Continued …</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=421eca37df2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>