Browse Source

update view mode construction

main
ghost 9 months ago
parent
commit
d3d810ee9c
  1. 238
      src/server.php

238
src/server.php

@ -392,149 +392,151 @@ $server->setHandler(
) { ) {
if ($record['transaction'] == $attribute[1]) if ($record['transaction'] == $attribute[1])
{ {
// Raw mode // View mode
if ('raw' == $request->getQuery()) switch ($request->getQuery())
{ {
// Transaction ID case 'raw':
$result[] = null;
$result[] = sprintf(
'# %s',
$record['transaction']
);
$result[] = null; // Transaction ID
$result[] = sprintf( $result[] = null;
'## %s', $result[] = sprintf(
$config->geminiapp->string->data '# %s',
); $record['transaction']
);
// Key $result[] = null;
$result[] = null; $result[] = sprintf(
$result[] = sprintf( '## %s',
'### %s', $config->geminiapp->string->data
$config->geminiapp->string->key );
);
// Key
$result[] = null;
$result[] = sprintf(
'### %s',
$config->geminiapp->string->key
);
$result[] = '```'; $result[] = '```';
$lines = []; $lines = [];
foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line) foreach ((array) explode(PHP_EOL, (string) $record['key']) as $line)
{ {
$lines[] = preg_replace( $lines[] = preg_replace(
'/^```/', '/^```/',
' ```', ' ```',
$line $line
);
}
$result[] = implode(
PHP_EOL,
$lines
); );
}
$result[] = implode( $result[] = '```';
PHP_EOL,
$lines
);
$result[] = '```'; // Value
$result[] = null;
$result[] = sprintf(
'### %s',
$config->geminiapp->string->value
);
// Value $result[] = '```';
$result[] = null;
$result[] = sprintf(
'### %s',
$config->geminiapp->string->value
);
$result[] = '```'; $lines = [];
$lines = []; foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line)
{
$lines[] = preg_replace(
'/^```/',
' ```',
$line
);
}
foreach ((array) explode(PHP_EOL, (string) $record['value']) as $line) $result[] = implode(
{ PHP_EOL,
$lines[] = preg_replace( $lines
'/^```/',
' ```',
$line
); );
}
$result[] = implode( $result[] = '```';
PHP_EOL,
$lines
);
$result[] = '```'; // Meta
$result[] = null;
$result[] = sprintf(
'## %s',
$config->geminiapp->string->meta
);
// Meta // Time
$result[] = null; $result[] = null;
$result[] = sprintf( $result[] = sprintf(
'## %s', '### %s',
$config->geminiapp->string->meta $config->geminiapp->string->time
); );
// Time $result[] = null;
$result[] = null; $result[] = date(
$result[] = sprintf( 'Y-m-d',
'### %s', $record['time']
$config->geminiapp->string->time );
);
$result[] = null; // Block
$result[] = date( $result[] = null;
'Y-m-d', $result[] = sprintf(
$record['time'] '### %s',
); $config->geminiapp->string->block
);
// Block $result[] = null;
$result[] = null; $result[] = $record['block'];
$result[] = sprintf(
'### %s',
$config->geminiapp->string->block
);
$result[] = null; break;
$result[] = $record['block'];
}
// Reader mode default:
else
{ // Key
// Key $result[] = null;
$result[] = null; $result[] = sprintf(
$result[] = sprintf( '# %s',
'# %s', trim(
trim( preg_replace( // single-line
preg_replace( // single-line '/[\s]+/',
'/[\s]+/', ' ',
' ', $record['key']
$record['key'] )
) )
) );
);
// Value // Value
$result[] = null; $result[] = null;
$result[] = trim( $result[] = trim(
preg_replace( preg_replace(
[ [
'/(^|\s+)(#|\*|```|=>)/', // escape gemini text '/(^|\s+)(#|\*|```|=>)/', // escape gemini text
'/[\n\r]{3,}/', // remove extra breaks '/[\n\r]{3,}/', // remove extra breaks
], ],
[ [
'$1 $2', '$1 $2',
PHP_EOL . PHP_EOL, PHP_EOL . PHP_EOL,
], ],
$record['value'] $record['value']
) )
); );
// Time // Time
$result[] = null; $result[] = null;
$result[] = sprintf( $result[] = sprintf(
'%s in %d', '%s in %d',
date( date(
'Y-m-d', 'Y-m-d',
$record['time'] $record['time']
), ),
$record['block'] $record['block']
); );
} }
// Footer // Footer

Loading…
Cancel
Save