Browse Source

implement reader/raw modes

main
ghost 9 months ago
parent
commit
180e654f08
  1. 11
      example/config.json
  2. 152
      src/server.php

11
example/config.json

@ -28,7 +28,16 @@ @@ -28,7 +28,16 @@
"results":"Results",
"older":"Older",
"newer":"Newer",
"nothing":"Nothing"
"nothing":"Nothing",
"block":"Block",
"time":"Time",
"data":"Data",
"meta":"Meta",
"view":
{
"raw":"Raw data",
"reader":"Reader"
}
}
},
"manticore":

152
src/server.php

@ -273,34 +273,28 @@ $server->setHandler( @@ -273,34 +273,28 @@ $server->setHandler(
// Key
$result[] = sprintf(
'### %s',
trim(
preg_replace( // single-line
'/[\s]+/',
' ',
$record['key']
)
)
);
// Value
$result[] = sprintf(
'``` %s',
$config->geminiapp->string->value
);
$lines = [];
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
$result[] = implode(
PHP_EOL,
$lines
$result[] = null;
$result[] = trim(
preg_replace( // remove extra breaks
'/[\n\r]{3,}/',
PHP_EOL . PHP_EOL,
$record['value']
)
);
$result[] = '```';
// Link
$result[] = null;
$result[] = sprintf(
'=> /%s %s in %d',
$record['transaction'],
@ -415,18 +409,54 @@ $server->setHandler( @@ -415,18 +409,54 @@ $server->setHandler(
) {
if ($record['transaction'] == $attribute[1])
{
// Header
// Raw mode
if ('raw' == $request->getQuery())
{
// Transaction ID
$result[] = sprintf(
'# %s',
$record['key']
$record['transaction']
);
// Body
$result[] = sprintf(
'``` %s',
'## %s',
$config->geminiapp->string->data
);
// Key
$result[] = sprintf(
'### %s',
$config->geminiapp->string->key
);
$result[] = '```';
$lines = [];
foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
$result[] = implode(
PHP_EOL,
$lines
);
$result[] = '```';
// Value
$result[] = sprintf(
'### %s',
$config->geminiapp->string->value
);
$result[] = '```';
$lines = [];
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line)
@ -445,6 +475,59 @@ $server->setHandler( @@ -445,6 +475,59 @@ $server->setHandler(
$result[] = '```';
// Meta
$result[] = sprintf(
'## %s',
$config->geminiapp->string->meta
);
// Time
$result[] = sprintf(
'### %s',
$config->geminiapp->string->time
);
$result[] = date(
'Y-m-d',
$record['time']
);
// Block
$result[] = sprintf(
'### %s',
$config->geminiapp->string->block
);
$result[] = $record['block'];
}
// Reader mode
else
{
// Key
$result[] = sprintf(
'# %s',
trim(
preg_replace( // single-line
'/[\s]+/',
' ',
$record['key']
)
)
);
// Value
$result[] = trim(
preg_replace( // remove extra breaks
'/[\n\r]{3,}/',
PHP_EOL . PHP_EOL,
$record['value']
)
);
// Time
$result[] = null;
$result[] = sprintf(
'%s in %d',
date(
@ -453,6 +536,7 @@ $server->setHandler( @@ -453,6 +536,7 @@ $server->setHandler(
),
$record['block']
);
}
// Footer
$result[] = sprintf(
@ -460,6 +544,24 @@ $server->setHandler( @@ -460,6 +544,24 @@ $server->setHandler(
$config->geminiapp->string->navigation
);
if ('raw' == $request->getQuery())
{
$result[] = sprintf(
'=> /%s %s',
$record['transaction'],
$config->geminiapp->string->view->reader
);
}
else
{
$result[] = sprintf(
'=> /%s?raw %s',
$record['transaction'],
$config->geminiapp->string->view->raw
);
}
$result[] = sprintf(
'=> /%s %s',
$record['namespace'],

Loading…
Cancel
Save