PlanetPlanet
www.tanabutr.co.th/photobook
เรื่องเก่าเล่าใหม่เรื่อง PlanetPlanet อีกครั้ง. มันก็เป็นเวลากว่า 1 ปีแล้วที่เรามี Planet TLWG ไว้ใน LTN. วันนี้เป็นลักษณะมาทบทวนดูว่าสร้าง Planet อย่างไร. จริงๆแล้วพอทำ Planet เสร็จก็ไม่ได้ไปดูแลอะไรมันมากมายเพราะมันก็ยังใช้ได้อยู่อย่างนั้น แต่ตอนนี้ก็คงมีอะไรเปลี่ยนแปลงไปพอควรเหมือนกัน.
ขั้นแรกดาว์นโหลด PlanetPlanet จาก planetplanet.org เผอิญเขาใช้ Arch เป็นตัวควบคุมรหัสต้นฉบับ คือขี้เกียจไปเรียนวิธีใช้ arch ก็เลยดาว์นโหลด planet-nightly.tar.bz2 หมายถึงมีคนเอารหัสต้นฉบับมาทำเป็นอาร์ไคฟทุกคืนไว้ให้ เอาอันนี้มาใช้ดีกว่า.
กระจายไฟล์ที่อยู่ในอาร์ไคฟนั้นออกมาก็จะได้ไดเรกทอรี planet-nightly.
$ tar jxvf planet-nightly.tar.bz2 $ cd planet-nightly $ ls AUTHORS README examples/ output/ ChangeLog THANKS fancy-examples/ planet.py* INSTALL TODO feedparser.py planetlib.py* Makefile compat_logging/ htmltmpl.py timeoutsocket.py
จะย้ายไดเรกทอรี planet-nightly ไปอยู่ที่ไหนก็ได้เพราะเวลาใช้งานจริงแล้วจะต้องรัน python แล้วให้มันเขียนไฟล์หน้า planet ให้ในที่ที่ต้องการ.
ไฟล์ตั้งค่าเริ่มต้นที่่ต้องแก้ไขคือ config.ini ซึ่งจะอยู่ในไดเรกทอรี examples และ fancy-examples. แต่จริงๆแล้วเราจะใช้ fancy-example/config.ini เพราะเวลาสร้างหน้า planet มันจะดูสวยกว่า. สรุปว่าแก้ไฟล์ fancy-examples/config.ini ส่วนไฟล์ example/config.ini ไม่ได้ใช้อะไร.
เรามาดูของจริงกันเลยดีกว่าที่ Planet TLWG มี config.ini กันอย่างไร
# Planet configuration file # # This illustrates some of Planet's fancier features with example. # Every planet needs a [Planet] section [Planet] # name: Your planet's name # link: Link to the main page # owner_name: Your name # owner_email: Your e-mail address name = Planet TLWG link = http://linux.thai.net/planet owner_name = Thai Linux Working Group owner_email = webmaster@linux.thai.net # cache_directory: Where cached feeds are stored # log_level: One of DEBUG, INFO, WARNING, ERROR or CRITICAL cache_directory = cache log_level = DEBUG # template_files: Space-separated list of output template files template_files = fancy-examples/index.html.tmpl examples/rss20.xml.tmpl examples /rss10.xml.tmpl examples/opml.xml.tmpl examples/foafroll.xml.tmpl # The following provide defaults for each template: # output_dir: Directory to place output files # items_per_page: How many items to put on each page # days_per_page: How many complete days of posts to put on each page # This is the absolute, hard limit (over the item limit) # date_format: strftime format for the default 'date' template variable output_dir = /var/www/planet items_per_page = 60 days_per_page = 0 # date_format = %B %d, %Y %I:%M %p date_format = %e %B %Ey %H:%M +0700 # To define a different value for a particular template you may create # a section with the same name as the template file's filename (as given # in template_files). # Provide no more than 7 days articles on the front page [fancy-examples/index.html.tmpl] items_per_page = 30 # Options placed in the [DEFAULT] section provide defaults for the feed # sections. Placing a default here means you only need to override the # special cases later. [DEFAULT] # Hackergotchi default size. # If we want to put a face alongside a feed, and it's this size, we # can omit these variables. facewidth = 65 faceheight = 85 # Any other section defines a feed to subscribe to. The section title # (in the []s) is the URI of the feed itself. A section can also be # have any of the following options: # # name: Name of the feed (defaults to the title found in the feed) # offset: Number of hours (+ or -) the feed's times tend to be out # # Additionally any other option placed here will be available in # the template (prefixed with channel_ for the Items loop). We use # this trick to make the faces work -- this isn't something Planet # "natively" knows about. Look at fancy-examples/index.html.tmpl # for the flip-side of this. # ต่อจากนี้ก็เป็นรายการ FEED ของแต่ละคน[http://bact.blogspot.com/atom.xml] name = bact face = bact.jpg facewidth = 80 faceheight = 80 ...
ส่วนที่สำคัญและต้องแก้ไข ผมเขียนเป็นสีแดงไว้เรียบร้อยแล้วครับ. ตรง output_dir เป็นที่ระบุไดเรกทอรีของหน้า planet ซึ่งในกรณีสมมตินี้ึคือ /var/www/planet. ตรงนี้จะต้องก็อปปี้ไฟล์และไดเรกทอรีทุกอย่างที่อยู่ใน planet-nightly/output ไปไว้ด้วย. ก็จะมีรูปภาพ (images) และ CSS ซึ่งเอาไว้แก้ไขหน้าตาได้.
ไฟล์ที่สำคัญอีกตัวหนึ่งคือ fancy-examples/index.html.tmpl เป็นไฟล์ template. การวางหน้า, โลโก้, สโลแกน อะไรพวกนี้เขียนไว้ในไฟล์นี้. ตัวอย่างไฟล์ index.html.tmpl ที่ใช้กับ Planet TLWG ครับ. ไฟล์ template นี้คุณเทพแก้ไปเยอะเหมือนกันจนได้เลย์เอาท์แบบที่เห็นกันทุกวันนี้. ส่วน FEED ที่เป็น RSS, ATOM ที่ใช้ก็จะใช้การลงรหัสแบบ UTF-8.
วิธีรันก็สั่งคำสั่ง
$ cd planet-nightly $ python planet.py fancy-examples/config.ini
แล้วมันก็จะสร้างหน้า planet คือหน้า index.html ไว้ที่ไดเรกทอรีที่ระบุด้วยตัวแปร output_dir. วิธีการทำให้มันอัปเดทหน้า planet ตลอดก็เอาไปใส่ใน crontab ครับ.
ว่างๆก็ลองไป Planet ในไซด์ตัวเองดูก็ได้นะครับ.
Comments: blogger