λ

Menu

  • Home
  • Archives
  • Tags
  • About Me
  • RSS
May 21, 2021

วิธีการใช้ Cryogen สำหรับสร้าง static website

  1. Cryogen
  2. สิ่งที่ต้องมี
  3. การใช้งาน
    1. สร้างไซต์ใหม่
    2. รัน server ขึ้นมา
    3. ตั้งค่าต่างๆ ของเว็บไซต์
  4. เอาเว็บเราไปอัพไว้บนโฮสติ้ง

Cryogen

CRYOGEN เป็น

  • เครื่องมือสำหรับใช้สร้าง static site ประเภท blogging
  • พัฒนาโดยใช้ภาษา Clojure
  • รองรับการเขียนโดยใช้ Markdown และ AsciiDoc
  • มี syntax highlight สำหรับแสดงผลโค้ด
  • และอื่นๆ

สิ่งที่ต้องมี

  • Clojure
  • Leiningen เวอร์ชัน 2.5.0 ขึ้นไป

การใช้งาน

สร้างไซต์ใหม่

โดยการใช้ Cryogen template:

lein new cryogen my-blog

หรือ อีกวิธี ใช้ clj-new:

clojure -X:new create :template cryogen :name me.my-blog

รัน server ขึ้นมา

เราสามารถรันเว็บขอเราขึ้นมาดูได้ อยู่ในไดเรกทอรี่ my-blog โดยใช้ Leiningen:

lein serve # หรือ lein serve-fast

หรือ tools-deps:

clojure -X:serve # or clojure -X:serve-fast

เมื่อ server start ขึ้นมาแล้ว ใช้ browser เปิดไปที่ localhost:3000

ตัว server จะ monitor การแก้ไขไฟล์ที่อยู่ในโฟลเดอร์ content และ themes และ คอมไพล์ให้ใหม่โดยอัตโนมัติ. The *-fast variants perform fast but partial compilation of only the changed page/post.

หรือถ้าอยากจะ generate เว็บโดยที่ไม่ต้องรัน server ขึ้นมาเลยก็ทำได้ โดยใช้คำสั่ง:

lein run

หรือ:

clojure -M:build

ตั้งค่าต่างๆ ของเว็บไซต์

เราสามารถตั้งค่าต่างๆ ของเว็บไซต์ได้ โดยแก้ไขไฟล์ content/config.edn, ซึ่งมีค่าต่างๆ ประมาณนี้:

{:site-title                   "My Awesome Blog"
 :author                       "Bob Bobbert"
 :description                  "This blog is awesome"
 :site-url                     "http://blogawesome.com/"
 :post-root                    "posts"
 :page-root                    "pages"
 :post-root-uri                "posts-output"
 :page-root-uri                "pages-output"
 :tag-root-uri                 "tags-output"
 :author-root-uri              "authors-output"
 :public-dest                  "public"
 :blog-prefix                  "/blog"
 :rss-name                     "feed.xml"
 :rss-filters                  ["cryogen"]
 :recent-posts                 3
 :post-date-format             "yyyy-MM-dd"
 :archive-group-format         "yyyy MMMM"
 :sass-src                     []
 :sass-path                    "sass"
 :theme                        "blue"
 :resources                    ["img"]
 :keep-files                   [".git"]
 :disqus?                      false
 :disqus-shortname             ""
 :ignored-files                [#"\.#.*" #".*\.swp$"]
 :previews?                    false
 :posts-per-page               5
 :blocks-per-preview           2
 :clean-urls                   :trailing-slash
 :collapse-subdirs?            false
 :hide-future-posts?           true
 :klipse                       {}
 :description-include-elements #{:p :h1 :h2 :h3 :h4 :h5 :h6}
 :debug?                       false}

รายละเอียดเกี่ยวกับค่าต่างๆ นั้น ไปหาอ่านเอาที่เว็บ http://cryogenweb.org/docs/configuration.html

เอาเว็บเราไปอัพไว้บนโฮสติ้ง

หลังจาก generate แล้ว ไฟล์ที่เราต้องการนั้นจะอยู่ในโฟลเดอร์ public สิ่งที่ต้องทำก็คือ copy ไฟล์ทั้งหมดไปไว้ที่โฟลเดอร์ที่อยู่บนโฮสติ้งที่รันด้วย Nginx หรือ Apache

ตัวอย่างการตั้งค่า Nginx ในไฟล์ /etc/nginx/sites-available/default:

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  server_name localhost <yoursite.com> <www.yoursite.com>;

  access_log  /var/log/blog_access.log;
  error_log   /var/log/blog_error.log;

  location / {
    alias       /var/blog/;
    error_page  404 = /404.html;
  }
}

แก้ส่วน yoursite.com ไปเป็นชื่อโดเมนของเรา โดยไฟล์ที่เรา copy มานั้นอยู่ในโฟลเดอร์ /var/blog/ บน server

ข้อมูลเพิ่มเติมสามารถไปดูได้ที่ หน้านี้.


Tags: cryogen clojure

« Clojure Ring เบื้องต้น [1]
Glosa static integration

{{ comments.length }} comments

New comment

Reply  {{ formatEllipsisAuthor(replyComment.author) }}

I accept the policy of Data Protection.

Write the first comment


Copyright © 2023 Phondanai Khanti

Powered by Cryogen | Free Website Template by Download Website Templates