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 @@
"results":"Results", "results":"Results",
"older":"Older", "older":"Older",
"newer":"Newer", "newer":"Newer",
"nothing":"Nothing" "nothing":"Nothing",
"block":"Block",
"time":"Time",
"data":"Data",
"meta":"Meta",
"view":
{
"raw":"Raw data",
"reader":"Reader"
}
} }
}, },
"manticore": "manticore":

204
src/server.php

@ -273,34 +273,28 @@ $server->setHandler(
// Key // Key
$result[] = sprintf( $result[] = sprintf(
'### %s', '### %s',
$record['key'] trim(
preg_replace( // single-line
'/[\s]+/',
' ',
$record['key']
)
)
); );
// Value // Value
$result[] = sprintf( $result[] = null;
'``` %s', $result[] = trim(
$config->geminiapp->string->value preg_replace( // remove extra breaks
); '/[\n\r]{3,}/',
PHP_EOL . PHP_EOL,
$lines = []; $record['value']
)
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
$result[] = implode(
PHP_EOL,
$lines
); );
$result[] = '```';
// Link // Link
$result[] = null;
$result[] = sprintf( $result[] = sprintf(
'=> /%s %s in %d', '=> /%s %s in %d',
$record['transaction'], $record['transaction'],
@ -415,44 +409,134 @@ $server->setHandler(
) { ) {
if ($record['transaction'] == $attribute[1]) if ($record['transaction'] == $attribute[1])
{ {
// Header // Raw mode
$result[] = sprintf( if ('raw' == $request->getQuery())
'# %s', {
$record['key'] // Transaction ID
); $result[] = sprintf(
'# %s',
$record['transaction']
);
// Body $result[] = sprintf(
$result[] = sprintf( '## %s',
'``` %s', $config->geminiapp->string->data
$config->geminiapp->string->value );
);
$lines = []; // Key
$result[] = sprintf(
'### %s',
$config->geminiapp->string->key
);
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) $result[] = '```';
{
$lines[] = preg_replace( $lines = [];
'/^```/',
' ```', foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line)
$line {
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
$result[] = implode(
PHP_EOL,
$lines
); );
}
$result[] = implode( $result[] = '```';
PHP_EOL,
$lines
);
$result[] = '```'; // Value
$result[] = sprintf(
'### %s',
$config->geminiapp->string->value
);
$result[] = sprintf( $result[] = '```';
'%s in %d',
date( $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', 'Y-m-d',
$record['time'] $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 // Footer
$result[] = sprintf( $result[] = sprintf(
@ -460,6 +544,24 @@ $server->setHandler(
$config->geminiapp->string->navigation $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( $result[] = sprintf(
'=> /%s %s', '=> /%s %s',
$record['namespace'], $record['namespace'],

Loading…
Cancel
Save