Browse Source

implement reader/raw modes

main
ghost 8 months ago
parent
commit
180e654f08
  1. 11
      example/config.json
  2. 204
      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":

204
src/server.php

@ -273,34 +273,28 @@ $server->setHandler( @@ -273,34 +273,28 @@ $server->setHandler(
// Key
$result[] = sprintf(
'### %s',
$record['key']
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,44 +409,134 @@ $server->setHandler( @@ -415,44 +409,134 @@ $server->setHandler(
) {
if ($record['transaction'] == $attribute[1])
{
// Header
$result[] = sprintf(
'# %s',
$record['key']
);
// Raw mode
if ('raw' == $request->getQuery())
{
// Transaction ID
$result[] = sprintf(
'# %s',
$record['transaction']
);
// Body
$result[] = sprintf(
'``` %s',
$config->geminiapp->string->value
);
$result[] = sprintf(
'## %s',
$config->geminiapp->string->data
);
$lines = [];
// Key
$result[] = sprintf(
'### %s',
$config->geminiapp->string->key
);
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
$result[] = '```';
$lines = [];
foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
$result[] = implode(
PHP_EOL,
$lines
);
}
$result[] = implode(
PHP_EOL,
$lines
);
$result[] = '```';
$result[] = '```';
// Value
$result[] = sprintf(
'### %s',
$config->geminiapp->string->value
);
$result[] = sprintf(
'%s in %d',
date(
$result[] = '```';
$lines = [];
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
$result[] = implode(
PHP_EOL,
$lines
);
$result[] = '```';
// Meta
$result[] = sprintf(
'## %s',
$config->geminiapp->string->meta
);
// Time
$result[] = sprintf(
'### %s',
$config->geminiapp->string->time
);
$result[] = date(
'Y-m-d',
$record['time']
),
$record['block']
);
);
// 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(
'Y-m-d',
$record['time']
),
$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