ä»åã¯ã.md
ãã¡ã¤ã«ã«Markdownå½¢å¼ã§æç« ãæ¸ãã¦ããããããApache httpdãnginxã§ãã¹ããããã©ã¦ã¶ããã¢ã¯ã»ã¹ããã¨HTMLã«å¤æããã¦è¡¨ç¤ºãããMarkdownã³ã³ãã¼ã¿ã¢ã¸ã¥ã¼ã«ãmrubyã§æ¸ãæ¹æ³ãç´¹ä»ãããã¨æãã¾ãã
Markdownã®ããã¹ãå½¢å¼ã§ä¿åãã¦ãããã¡ã¤ã«ãé©å½ã«Apacheä¸ã§é ä¿¡ããã°ããã©ã¦ã¶ä¸ã§HTMLã§ç¶ºéºã«é²è¦§ã§ããã¨ãã£ãããããã¢ã¬ãWebãµã¼ããæ¡å¼µãã¦å®è£ ãã¦ã¿ããã¨ãã話ã§ããèªåã®éçºç°å¢ããã¼ã«ã«ç°å¢ã®ã¡ã¢ç½®ãå ´ã«ãè¯ãããããã¾ããã
Apacheã¢ã¸ã¥ã¼ã«ãnginxã¢ã¸ã¥ã¼ã«ã§å¹¾ã¤ããããã£ãæ©è½ãæä¾ããã¢ã¸ã¥ã¼ã«ã¯ããã¨æãã®ã§ãããããå°ãç¬èªã§æ¹è¯ãããã£ãããCè¨èªã§å®è£ ããã«ãã£ã¨ç°¡åã«èªåã§æ¸ãã¦ã¿ãããã¨ãã£ãè¦æ±ã«æ¬ã¨ã³ããªãèªãã¨çããããã¨æãã¾ãã
ãã¡ãããããã®æ©è½ã®å®è£ ã¯ãåãéçºãã¦ããApacheã¯mod_mrubyããnginxã¯ngx_mrubyã使ã£ã¦å®è£ ãã¦ã¿ã¾ãããã
Apacheã§Markdownã³ã³ãã¼ã¿ã¢ã¸ã¥ã¼ã«ãmrubyã§å®è£
ã§ã¯æ©éå®è£ ãã¦ã¿ã¾ãããã
ã¾ãã¯ãhttpd.conf
ãconf.d/markdown.conf
ã®ãããªè¨å®ãã¡ã¤ã«ã«ä»¥ä¸ã®ããã«Apacheã¢ã¸ã¥ã¼ã«ä»£ããã«ããã¯ããRubyã¹ã¯ãªããã®ãã¹ãæ¸ãã¾ãã
<FilesMatch "^.*\.md$"> AddType text/html .md SetOutputFilter mruby mrubyOutputFilter /path/to/filter.rb </FilesMatch>
ç¶ãã¦ããã®Rubyã¹ã¯ãªãã/path/to/filter.rb
ã«ä»¥ä¸ã®ããã«Markdownå¤æå¦çãæ¸ãã¾ãã
# ãã®ã¹ã¯ãªãããåãããã«ã¦ã§ã¢ã®ãã§ã㯠if server_name == "NGINX" Server = Nginx elsif server_name == "Apache" Server = Apache end f = Server::Filter.new # Markdownå¤æã®æºåãã¹ã¿ã¤ã«ã®èªè¾¼ç css = "https://gist.github.com/andyferra/2554919/raw/2e66cabdafe1c9a7f354aa2ebf5bc38265e638e5/github.css" title = "markdown" md = Discount.new css, title # MarkdownããHTMLã«å¤æãããã¼ã¿ãã¬ã¹ãã³ã¹ãã¼ã¿ã«ä¸æ¸ã f.body = md.md2html f.body
ã³ã¼ãã®å 容ã¯èª¬æããã¾ã§ããªãã§ããããããã ãã§ãMarkdownã³ã³ãã¼ã¿ã¢ã¸ã¥ã¼ã«ãä½æã§ãã¾ãããä¾ãã°ã以ä¸ã®ãããªMarkdownãã¡ã¤ã«ã«ã¢ã¯ã»ã¹ããã¨ã
# Section ## aaa - hoge - foo ## bbb __code__ a = 1 b = a + 1
以ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
ç°¡åã§ãããCè¨èªã§æ¸ãå ´åã¨æ¯ã¹ãã¨ã³ã¼ãã®éãå¤§å¹ ã«å°ãªãäºããããã¾ãã
nginxã§ãMarkdownã³ã³ãã¼ã¿ã¢ã¸ã¥ã¼ã«ãmrubyã§å®è£ ãã¦ã¿ã
ç¶ãã¦nginxã§ãåæ§ã®æ©è½ãå®è£ ãã¦ã¿ã¾ãããã
nginxã§ã¯ãmod_mrubyã®ãããã«ngx_mrubyã使ãã¾ããããã¤ã³ã¹ãã¼ã«æ¹æ³çã¯GitHubã®Wikiã御覧ãã ãããã¾ããDockerfileã使ã£ãç°¡åãªã¤ã³ã¹ãã¼ã«æ¹æ³ãWikiã«æ¸ãã¦ããã®ã§ããã£ã¨è©¦ãã«ã¯ãããã使ãã®ãè¯ãããããã¾ããã
ã¾ãã¯ã以ä¸ã®ãããªè¨å®ãnginx.conf
ã«æ¸ãã¾ãã
location ~ \.md$ {
mruby_output_filter /path/to/filter.rb;
}
ç¶ãã¦ãmod_mrubyã¨åæ§ã«/path/to/filter.rb
ã«ã³ã³ãã¼ãã®å¦çãå®è£
ãã¾ãã
# ãã®ã¹ã¯ãªãããåãããã«ã¦ã§ã¢ã®ãã§ã㯠if server_name == "NGINX" Server = Nginx elsif server_name == "Apache" Server = Apache end f = Server::Filter.new # Markdownå¤æã®æºåãã¹ã¿ã¤ã«ã®èªè¾¼ç css = "https://gist.github.com/andyferra/2554919/raw/2e66cabdafe1c9a7f354aa2ebf5bc38265e638e5/github.css" title = "markdown" md = Discount.new css, title # MarkdownããHTMLã«å¤æãããã¼ã¿ãã¬ã¹ãã³ã¹ãã¼ã¿ã«ä¸æ¸ã f.body = md.md2html f.body
ããï¼mod_mrubyã®æã®mrubyã®å®è£ ã¨å ¨ãåãã§ããã
ãããªãã§ãããã®ããã«ãmod_mrubyã¨ngx_mrubyã¯ããç¨åº¦ã¯ã©ã¹ãã¡ã½ããã®å®è£ ã®äºææ§ãæããã¤ã¤ä¸¦è¡ãã¦éçºãã¦ãã¾ãã®ã§ããããã£ãå®è£ ãå¯è½ã«ãªãã¾ãããã®ããã«éçºãã¦ãããã¨ã§ãmod_mrubyã§å¦ãã ã¡ã½ãããå®è£ ã®ã³ãã¨ãã£ãè³ç£ã¯ãããä¸æ¹ã®ngx_mrubyã§ãããç¨åº¦æ´»ããããã¨ããç¹å¾´ãããã¾ãã
å½ç¶ããã®.md
ãã¡ã¤ã«ã«ã¢ã¯ã»ã¹ããã¨ã以ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
mod_mrubyã®æã¨åæ§ã§ããã
Apacheã¢ã¸ã¥ã¼ã«ãnginxã¢ã¸ã¥ã¼ã«ãCè¨èªã§æ¸ãäºãªããããªã«ç°¡åã«ããã¾ããã
ã¾ã¨ã
以ä¸ã®ããã«ãä»åã¯Apacheã¨nginxã®Markdownã³ã³ãã¼ã¿ã¢ã¸ã¥ã¼ã«ãCè¨èªã§å®è£ ããã®ã§ã¯ãªããmod_mrubyã¨ngx_mrubyã使ã£ã¦mrubyã§å®è£ ãã¦ã¿ã¾ããã
Cè¨èªã§ãããããå®è£ ããäºããã人ã¯ããã®å®è£ ã®ç°¡åãã«ã³ã£ããããã®ã§ã¯ãªãã§ããããã
ãã®ããã«ãmod_mrubyãngx_mrubyã使ãã°ãApacheãnginxã®ã¢ã¸ã¥ã¼ã«ã¨ããæ·å± ã®é«ãã£ãéçºããé常ã«ç°¡åã«ã§ããããã«ãªãã¾ããã¾ããmod_mrubyã¨ngx_mrubyã¯ãmrubyã®è»½éãªç¹å¾´ããããã¦ãã¹ã¯ãªããè¨èªã«ããå®è£ ã«ãé¢ãããããªãé«éã«åä½ããããã«å®è£ ãã¦ããã®ã§ãçç£æ§ã¨æ§è½ã®ãã©ã³ã¹ãåããããã®ã§ã¯ãªãã§ããããã
é常ã«ç°¡åã«Webãµã¼ãã®æ¡å¼µãæ¸ãã¾ãã®ã§ãã¾ãã¯èªèº«ã®ãã¼ã«ã«ãµã¼ããæ¤è¨¼ç°å¢çã§ãèªåç¨ã®ä¾¿å©ãªApacheï¼nginxï¼ã¢ã¸ã¥ã¼ã«ãmrubyã§éçºãã¦éãã§ã¿ãã¨ãè²ã æãã®ã§ã¯ãªããã¨æãã¾ãï¼
ä¾ãã°ä»åã®Markdownã³ã³ãã¼ã¿ã®å®è£ ã«ã追å ã§å®è£ ãã¦éãã§ã¿ãã®ã楽ããã¨æãã¾ããä¼ã¿ã®æ¥ã¨ããµã¼ãå¼ã£ã¦éãã§ã¿ãã£ããªã¼ã¿ãããªæ¥ã«æ¯éæ¯éè²ã éãã§ã¿ã¦ãã ããï¼
è¨ãå¿ãã¦ãã¾ããããmod_mrubyãngx_mrubyã®ãã«ãã®éã«ãbuild_config.rbä¸ã§mruby-discountããªã³ã¯ããè¨å®ãã³ã¡ã³ãã§æ¸ãã¦ããã®ã§ãã®ã³ã¡ã³ããå¤ãã¦ãã«ããã¦ä¸ãããï¼