initial
This commit is contained in:
commit
49609bff65
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.db
|
||||
.direnv
|
26
flake.lock
Normal file
26
flake.lock
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1663850217,
|
||||
"narHash": "sha256-tp9nXo1/IdN/xN9m06ryy0QUAEfoN6K56ObM/1QTAjc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ae1dc133ea5f1538d035af41e5ddbc2ebcb67b90",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-unstable",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
53
flake.nix
Normal file
53
flake.nix
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
description = "openbsd.app: a tool to search OpenBSD packages";
|
||||
|
||||
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
supportedSystems =
|
||||
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
|
||||
in {
|
||||
packages = forAllSystems (system:
|
||||
let pkgs = nixpkgsFor.${system};
|
||||
in {
|
||||
thing = pkgs.stdenv.mkDerivation {
|
||||
pname = "openbsd.app";
|
||||
version = "v0.0.1";
|
||||
src = ./.;
|
||||
nativeBuildInputs = with pkgs.perlPackages; [
|
||||
perl
|
||||
Mojolicious
|
||||
MojoSQLite
|
||||
];
|
||||
buildInputs = with pkgs; [ perl ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
install -t openbsd.app.pl $out/bin
|
||||
'';
|
||||
};
|
||||
});
|
||||
|
||||
defaultPackage = forAllSystems (system: self.packages.${system}.thing);
|
||||
devShells = forAllSystems (system:
|
||||
let pkgs = nixpkgsFor.${system};
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
shellHook = ''
|
||||
PS1='\u@\h:\@; '
|
||||
echo "Perl `${pkgs.perl}/bin/perl --version`"
|
||||
'';
|
||||
buildInputs = with pkgs.perlPackages; [ PerlTidy ];
|
||||
nativeBuildInputs = with pkgs.perlPackages; [
|
||||
perl
|
||||
Mojolicious
|
||||
MojoSQLite
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
118
openbsd.app.pl
Normal file
118
openbsd.app.pl
Normal file
@ -0,0 +1,118 @@
|
||||
use Mojolicious::Lite -signatures;
|
||||
use Mojo::SQLite;
|
||||
use Data::Dumper;
|
||||
|
||||
#helper unstable => sub { state $sql = Mojo::SQLite->new('sqlite:unstable.db') };
|
||||
helper stable => sub { state $sql = Mojo::SQLite->new('sqlite:stable.db') };
|
||||
|
||||
my $query = q{
|
||||
SELECT
|
||||
FULLPKGNAME,
|
||||
FULLPKGPATH,
|
||||
COMMENT,
|
||||
DESCRIPTION,
|
||||
highlight(ports_fts, 2, '<b>', '</b>') AS COMMENT_MATCH,
|
||||
highlight(ports_fts, 3, '<b>', '</b>') AS DESCR_MATCH
|
||||
FROM ports_fts
|
||||
WHERE ports_fts MATCH ? ORDER BY rank;
|
||||
};
|
||||
|
||||
get '/' => sub ($c) {
|
||||
my $v = $c->validation;
|
||||
my $search = $c->param('search');
|
||||
#my $unstable = $c->param('unstable');
|
||||
|
||||
if ( defined $search && $search ne "" ) {
|
||||
return $c->render(text => 'Bad CSRF token!', status => 403) if $v->csrf_protect->has_error('csrf_token');
|
||||
|
||||
my $db = $c->stable->db;
|
||||
#$db = $c->unstable->db if defined $unstable;
|
||||
|
||||
my $results = $db->query($query, $search)->hashes;
|
||||
$c->render( template => 'results', search => $search, results => $results );
|
||||
}
|
||||
else {
|
||||
$c->render( template => 'index' );
|
||||
}
|
||||
};
|
||||
|
||||
app->start;
|
||||
__DATA__
|
||||
@@ layouts/default.html.ep
|
||||
<!doctype html>
|
||||
<html class="no-js" lang="">
|
||||
<head>
|
||||
<title>OpenBSD.app</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<meta name="description" content="OpenBSD package search">
|
||||
<style>
|
||||
body {
|
||||
font-family: Avenir, 'Open Sans', sans-serif;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
border: 1px solid;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
table {
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
.popup {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.result:hover~.popup {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="search">
|
||||
%= form_for '/' => begin
|
||||
%= text_field search => ""
|
||||
%= csrf_field
|
||||
%= submit_button 'Search...'
|
||||
% end
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<%== content %>
|
||||
<hr />
|
||||
<footer>
|
||||
OpenBSD.app
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ results.html.ep
|
||||
% layout 'default';
|
||||
Found <%= @$results %> reslts for for '<%= $search %>':
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Path</th>
|
||||
<th>Comment</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
% foreach my $result (@$results) {
|
||||
<tr>
|
||||
<td><%= $result->{FULLPKGPATH} %></td>
|
||||
<td><%== $result->{COMMENT_MATCH} %></td>
|
||||
<td><%== $result->{DESCR_MATCH} %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
|
||||
@@ index.html.ep
|
||||
% layout 'default';
|
||||
Welcome!
|
Loading…
Reference in New Issue
Block a user