2018-07-18 15:54:43 +00:00
/ * \
title : $ : / c o r e / m o d u l e s / s e r v e r / r o u t e s / g e t - t i d d l e r - h t m l . j s
type : application / javascript
module - type : route
GET / : title
\ * /
( function ( ) {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict" ;
exports . method = "GET" ;
exports . path = /^\/([^\/]+)$/ ;
exports . handler = function ( request , response , state ) {
var title = decodeURIComponent ( state . params [ 0 ] ) ,
tiddler = state . wiki . getTiddler ( title ) ;
if ( tiddler ) {
2018-12-01 13:30:00 +00:00
var renderType = tiddler . getFieldString ( "_render_type" ) ,
renderTemplate = tiddler . getFieldString ( "_render_template" ) ;
// Tiddler fields '_render_type' and '_render_template' overwrite
// system wide settings for render type and template
2018-07-18 15:54:43 +00:00
if ( state . wiki . isSystemTiddler ( title ) ) {
2018-12-01 13:30:00 +00:00
renderType = renderType || state . server . get ( "system-tiddler-render-type" ) ;
renderTemplate = renderTemplate || state . server . get ( "system-tiddler-render-template" ) ;
2018-07-18 15:54:43 +00:00
} else {
2018-12-01 13:30:00 +00:00
renderType = renderType || state . server . get ( "tiddler-render-type" ) ;
renderTemplate = renderTemplate || state . server . get ( "tiddler-render-template" ) ;
2018-07-18 15:54:43 +00:00
}
2018-12-01 13:30:00 +00:00
var text = state . wiki . renderTiddler ( renderType , renderTemplate , { parseAsInline : true , variables : { currentTiddler : title } } ) ;
2021-05-08 15:05:39 +00:00
2018-07-18 15:54:43 +00:00
// Naughty not to set a content-type, but it's the easiest way to ensure the browser will see HTML pages as HTML, and accept plain text tiddlers as CSS or JS
2021-05-08 15:05:39 +00:00
state . sendResponse ( 200 , { } , text , "utf8" ) ;
2018-07-18 15:54:43 +00:00
} else {
response . writeHead ( 404 ) ;
response . end ( ) ;
}
} ;
} ( ) ) ;