mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 08:57:55 +00:00
var/www/pages/index.php : more mime types, tidy-up
This commit is contained in:
parent
32427136b7
commit
a4c1bddd01
1 changed files with 20 additions and 19 deletions
|
@ -52,44 +52,45 @@ $file_url = implode("/", $parts);
|
||||||
# If this is a folder or just empty, we add 'index.html' to the URL:
|
# If this is a folder or just empty, we add 'index.html' to the URL:
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git ls-tree 'master:$file_url' > /dev/null\"";
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git ls-tree 'master:$file_url' > /dev/null\"";
|
||||||
exec($command, $output, $retval);
|
exec($command, $output, $retval);
|
||||||
if ($retval == 0) {
|
if ($retval === 0) {
|
||||||
if ($file_url == "" ) {
|
if ($file_url !== '') {
|
||||||
$file_url = "index.html";
|
$file_url .= '/';
|
||||||
} else {
|
$file_url .= "index.html";
|
||||||
$file_url .= "/index.html";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$ext = pathinfo($file_url, PATHINFO_EXTENSION);
|
$ext = pathinfo($file_url, PATHINFO_EXTENSION);
|
||||||
$ext = strtolower($ext);
|
$ext = strtolower($ext);
|
||||||
|
|
||||||
$mime_types = array(
|
$mime_types = array(
|
||||||
"svg" => "image/svg+xml",
|
"css" => "text/css",
|
||||||
"png" => "image/png",
|
"csv" => "text/csv",
|
||||||
|
"gif" => "image/gif",
|
||||||
|
"html" => "text/html",
|
||||||
|
"ico" => "image/x-icon",
|
||||||
|
"ics" => "text/calendar",
|
||||||
"jpg" => "image/jpeg",
|
"jpg" => "image/jpeg",
|
||||||
"jpeg" => "image/jpeg",
|
"jpeg" => "image/jpeg",
|
||||||
"gif" => "image/gif",
|
|
||||||
"js" => "application/javascript",
|
"js" => "application/javascript",
|
||||||
"html" => "text/html",
|
"json" => "application/json",
|
||||||
"css" => "text/css",
|
"pdf" => "application/pdf",
|
||||||
"ico" => "image/x-icon",
|
"png" => "image/png",
|
||||||
|
"svg" => "image/svg+xml",
|
||||||
|
"ttf" => "font/ttf",
|
||||||
|
"txt" => "text/plain",
|
||||||
"woff" => "font/woff",
|
"woff" => "font/woff",
|
||||||
"woff2" => "font/woff2",
|
"woff2" => "font/woff2",
|
||||||
"ttf" => "font/ttf"
|
"xml" => "text/xml"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (array_key_exists($ext, $mime_types)) {
|
if (array_key_exists($ext, $mime_types)) {
|
||||||
$mime_type = $mime_types[$ext];
|
header("Content-Type: " . $mime_types[$ext]);
|
||||||
} else {
|
} else {
|
||||||
$mime_type = "text/plain";
|
header("Content-Type: application/octet-stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Content-Type: " . $mime_type);
|
|
||||||
|
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:$file_url'\"";
|
|
||||||
|
|
||||||
## We are executing command twice (first for send_response-checking, then for actual raw output to stream),
|
## We are executing command twice (first for send_response-checking, then for actual raw output to stream),
|
||||||
## which seems wasteful, but it seems exec+echo cannot do raw binary output? Is this true?
|
## which seems wasteful, but it seems exec+echo cannot do raw binary output? Is this true?
|
||||||
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:$file_url'\"";
|
||||||
exec($command . " > /dev/null", $output, $retval);
|
exec($command . " > /dev/null", $output, $retval);
|
||||||
if ($retval != 0) {
|
if ($retval != 0) {
|
||||||
# Render user-provided 404.html if exists, generic 404 message if not:
|
# Render user-provided 404.html if exists, generic 404 message if not:
|
||||||
|
|
Loading…
Reference in a new issue