Show
Ignore:
Timestamp:
12/11/07 20:07:26 (5 years ago)
Author:
cho45
Message:

lang/javascript/blosxom.rhino/blosxom.rhino.cgi:

CGI キッカーを分離
文字化け対策を追加 (どうするのがスマートなのかわからない)

Location:
lang/javascript/blosxom.rhino
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/blosxom.rhino/blosxom.rhino.cgi

    r3048 r3053  
    1 #!/usr/bin/env rhino 
    2 // vim:ft=javascript: 
     1#!/bin/sh 
    32 
    4 function p (msg) { 
    5         try { 
    6                 print(uneval(msg)); 
    7         } catch (e) { 
    8                 print(String(msg)); 
    9         } 
    10 } 
     3RHINO="/usr/share/js.jar" 
    114 
    12 importPackage(java.lang); 
    13 importPackage(java.io); 
     5java -Dfile.encoding=UTF-8 -jar $RHINO blosxom.rhino.js 
    146 
    15 load("ejs.js"); 
    16  
    17 BlosxomRhino = function (config) { this.initialize(config) }; 
    18 BlosxomRhino.prototype = { 
    19         initialize : function (config) { 
    20                 this.config = config; 
    21         }, 
    22  
    23         run : function () { 
    24                 var entries = this.getEntries(); 
    25                 entries.sort(function (a, b) { 
    26                         return b.datetime.valueOf() - a.datetime.valueOf(); 
    27                 }); 
    28                 var template = new EJS(this._readLines("template.html").join("\n")); 
    29                 // p(entries); 
    30  
    31                 print(template.run({ 
    32                         title       : this.config.title, 
    33                         author      : this.config.author, 
    34                         home        : this.getenv("SCRIPT_NAME") || '/', 
    35                         path        : (this.getenv("SCRIPT_NAME") || '/').split("/").slice(-1)[0], 
    36                         server_root : "http://" + this.getenv("SERVER_NAME"), 
    37                         entries     : entries, 
    38                 })); 
    39         }, 
    40  
    41         getEntries : function () { 
    42                 function _getFiles (dir) { 
    43                         var ret = []; 
    44                         dir.listFiles().forEach(function (i) { 
    45                                 if (i.isDirectory()) { 
    46                                         ret = ret.concat(_getFiles(i)); 
    47                                 } else 
    48                                 if (i.getName().match(/\.txt$/)) { 
    49                                         ret.push(i); 
    50                                 } 
    51                         }); 
    52                         return ret; 
    53                 } 
    54  
    55                 var self = this; 
    56                 var files = _getFiles(File(self.config.data_dir)); 
    57                 var entries = files.map(function (i) { 
    58                         var content = self._readLines(i); 
    59                         return { 
    60                                 file     : i, 
    61                                 name     : String(i).replace(RegExp("^"+self.config.data_dir+"|\\..*$", "g"), ""), 
    62                                 datetime : new Date(i.lastModified()), 
    63                                 title    : String(content.shift()), 
    64                                 body     : content.join("\n"), 
    65                         }; 
    66                 }); 
    67                 return entries; 
    68         }, 
    69  
    70         _readLines : function (file) { 
    71                 var br = new BufferedReader( 
    72                         new InputStreamReader( 
    73                                 new FileInputStream(file), 
    74                                 "UTF-8" 
    75                         ) 
    76                 ); 
    77                 var ret = []; 
    78                 while (br.ready()) ret.push(br.readLine()); 
    79                 return ret; 
    80         }, 
    81  
    82         getenv : function (name) { 
    83                 return String(System.getenv(name)); 
    84         }, 
    85 }; 
    86  
    87 //print("Content-Type: text/plain"); 
    88 //print(""); 
    89 //p(String(System.getenv("USER"))); 
    90  
    91  
    92 //var files = File(Config.data_dir).listFiles( 
    93 //      FilenameFilter({ 
    94 //              accept: function (dir, name) { 
    95 //                      return (name.match(/\.txt$/)) 
    96 //              } 
    97 //      }) 
    98 //); 
    99 // 
    100 //p(files); 
    101 // 
    102 //var entries = files.map(function (i) { 
    103 //      p(i.lastModified()); 
    104 //      p(i.getName()); 
    105 //      return { 
    106 //              file : i, 
    107 //              name : String(i).replace(RegExp("^"+Config.data_dir+"|\\..*$", "g"), ""), 
    108 //              datetime : new Date(i.lastModified()), 
    109 //      }; 
    110 //}); 
    111 //p(entries); 
    112  
    113 new BlosxomRhino({ 
    114         title    : "Blosxo.Rhino!", 
    115         data_dir : "data", 
    116 }).run();