Browse Source

[WIP] First migration commit

master
Diane 2 years ago
parent
commit
2a7da6e04c
No known key found for this signature in database GPG Key ID: B13153D92467FCC1
  1. 3
      .gitignore
  2. 201
      LICENSE
  3. 13
      apps/search/.editorconfig
  4. 18
      apps/search/.gitignore
  5. 14
      apps/search/README.md
  6. 24
      apps/search/package.json
  7. 64
      apps/search/rollup.config.js
  8. 50
      apps/search/src/App.svelte
  9. 67
      apps/search/src/Search.svelte
  10. 11
      apps/search/src/main.js
  11. 4
      apps/search/src/stores.js
  12. 1194
      apps/search/yarn.lock
  13. 27
      composer.json
  14. 2274
      composer.lock
  15. 20
      config.php
  16. 112
      gulpfile.ts
  17. 16
      model.sql
  18. 51
      package.json
  19. 4
      public/.htaccess
  20. 12
      public/index.php
  21. 0
      public/keybase.txt
  22. 20
      routes.php
  23. 31
      site/assets/gpg/2018-11-26/artemix@artemix.org.pubkey.asc
  24. 31
      site/assets/gpg/2018-11-26/artemix@artemix.org.pubkey.asc.txt
  25. 0
      site/assets/gpg/diane@artemix.org.pubkey.asc
  26. 0
      site/assets/gpg/diane@artemix.org.pubkey.asc.txt
  27. 7
      src/Action.php
  28. 25
      src/Actions/About.php
  29. 52
      src/Actions/Article/Show.php
  30. 37
      src/Runner.php
  31. 19
      src/Services/Config.php
  32. 25
      src/Services/Database.php
  33. 23
      src/Services/HTML.php
  34. 31
      src/Services/Repositories/Article.php
  35. 82
      templates/about.html.twig
  36. 93
      templates/base.html.twig
  37. 11
      templates/fragments/head.html.twig
  38. 29
      todo.txt
  39. 16
      tsconfig.json
  40. 3258
      yarn.lock

3
.gitignore

@ -12,7 +12,6 @@ pom.xml.asc
.hg/
.idea/
node_modules/
public
.vscode/
.idea/
*.log
vendor

201
LICENSE

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2018 Artemis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

13
apps/search/.editorconfig

@ -1,13 +0,0 @@
# top-most EditorConfig file
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
[package.json]
indent_style = space
indent_size = 2

18
apps/search/.gitignore

@ -1,18 +0,0 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
.idea/
node_modules/
public/
.vscode/
.idea/
*.log

14
apps/search/README.md

@ -1,14 +0,0 @@
# search
Simple HTML search page,
based on a [lunr](https://lunrjs.com/) search index.
## Dev server configuration
The two environment variables `HOST` and `PORT` are available to customize both values.
To spin it up, run `yarn start`.
## Building and running in production mode
To create an optimised version of the app, run `yarn build`.

24
apps/search/package.json

@ -1,24 +0,0 @@
{
"name": "@artemix.org/search",
"version": "1.0.0",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public",
"prod": "yarn && yarn build"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^6.0.0",
"@types/lunr": "^2.3.2",
"rollup": "^1.12.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^5.1.2",
"svelte": "^3.0.0"
},
"dependencies": {
"lunr": "^2.3.8",
"sirv-cli": "^0.4.4"
}
}

64
apps/search/rollup.config.js

@ -1,64 +0,0 @@
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import { join } from 'path';
const root = join(__dirname, '../../');
const production = !process.env.ROLLUP_WATCH;
const outputConfigurations = {
dev: {
sourcemap: true,
file: 'public/search.js',
},
production: {
sourcemap: false,
file: `${root}/public/search.js`
}
};
export default {
input: 'src/main.js',
output: {
...outputConfigurations[production ? 'production' : 'dev'],
format: 'iife',
name: 'app',
},
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
}),
resolve({
browser: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs(),
!production && serve(),
!production && livereload('public'),
production && terser()
],
watch: {
clearScreen: false
}
};
function serve() {
let started = false;
return {
writeBundle() {
if (!started) {
started = true;
require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
}
}
};
}

50
apps/search/src/App.svelte

@ -1,50 +0,0 @@
<script>
import lunr from 'lunr';
import {database, dataset} from './stores';
import Search from './Search.svelte';
/** @var {URLSearchParams} urlParams */
export let urlParams;
export let databasePath;
let databaseLoad = loadDatabase(databasePath);
async function loadDatabase(path) {
const res = await fetch(path);
if (!res.ok) {
console.error(res);
const text = await res.text();
throw new Error(text);
}
const [set, idx] = await res.json();
database.set(lunr.Index.load(idx));
dataset.set(set);
}
function currentSearch() {
return urlParams.get('q') || '';
}
function updateQueryString(event) {
const query = event.detail.query;
// window.location
const url = new URL(window.location.origin + window.location.pathname);
if ('' !== query) {
url.searchParams.append('q', query);
}
window.history.pushState(null, null, url);
}
</script>
<main>
{#await databaseLoad}
<h1>Loading database index...</h1>
{:then _}
<Search search="{currentSearch()}" on:query={updateQueryString}/>
{:catch _}
<h1>Search load error</h1>
<p>An error occured during load. Unfortunately, that means that the search functionality isn't available right
now.</p>
<p>Meanwhile, you may want to check the <a href="/blog/">article list</a> if you want to find an article.</p>
{/await}
</main>

67
apps/search/src/Search.svelte

@ -1,67 +0,0 @@
<script>
import {onMount} from 'svelte';
import {database as searchIndex, dataset as articles} from './stores';
import {createEventDispatcher} from 'svelte';
export let search;
let searchBar;
const dispatch = createEventDispatcher();
function searchForTerm(term) {
// First, update the QueryString URL fragment to match the search...
dispatch('query', {
query: term,
});
// ... then, search
try {
if ('' === term) {
document.title = 'Search an article';
return [];
}
document.title = 'Results for "' + term + '"';
return $searchIndex.search(term).map(res => {
return {
...$articles[res.ref],
slug: res.ref,
};
});
} catch (e) {
console.error(e);
return [];
}
}
$: results = searchForTerm(search);
$: resultCount = results.length;
$: articleLabelPlural = resultCount > 1 ? 's' : '';
onMount(() => {
searchBar.focus();
});
</script>
<h1>Search an article (<a href="https://lunrjs.com/guides/searching.html" target="_blank" rel="noopener">help</a>)</h1>
<section style="display: flex;">
<input placeholder="Search an article.."
bind:this={searchBar}
bind:value={search}
style="flex: 1"/>
</section>
<p>{resultCount} article{articleLabelPlural} found</p>
<section class="mono">
{#each results as result, idx}
{#if idx !== 0}
<hr>
{/if}
<p class="date">{result.date} - <a href="/blog/{result.slug}.html">{result.title}</a></p>
{#if result.cat}
<p>Under category: {result.cat}</p>
{/if}
{/each}
</section>

11
apps/search/src/main.js

@ -1,11 +0,0 @@
import App from './App.svelte';
const app = new App({
target: document.getElementById('search-app'),
props: {
databasePath: '/blog/articles.idx',
urlParams: new URLSearchParams(window.location.search),
},
});
export default app;

4
apps/search/src/stores.js

@ -1,4 +0,0 @@
import { writable } from 'svelte/store';
export const database = writable(null);
export const dataset = writable(null);

1194
apps/search/yarn.lock
File diff suppressed because it is too large
View File

27
composer.json

@ -0,0 +1,27 @@
{
"name": "artemis/artemix.org",
"description": "My blog",
"type": "project",
"require": {
"leocavalcante/siler": "^1.7",
"twig/twig": "^3.0",
"php-di/php-di": "^6.0",
"ext-pdo": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"license": "Apache-2.0",
"authors": [
{
"name": "Diane",
"email": "diane@artemix.org"
}
],
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"App\\": "src"
}
}
}

2274
composer.lock
File diff suppressed because it is too large
View File

20
config.php

@ -0,0 +1,20 @@
<?php
defined('ROOT') || define('ROOT', realpath(__DIR__));
function needs($key) {
$value = getenv($key);
if (false === $value) {
throw new RuntimeException("No environment value found for required key $key");
}
return $value;
}
return [
'templates' => ROOT.'/templates',
'db' => [
'dsn' => needs(getenv('DB_DSN')),
'username' => getenv('DB_USERNAME') ?? null,
'password' => getenv('DB_PASSWORD') ?? null
]
];

112
gulpfile.ts

@ -1,112 +0,0 @@
import {config} from './config';
import {Env} from './builder/config';
import {FileManager} from "./builder/file";
import {ArticleManager} from "./builder/article-manager";
import {Renderer} from "./builder/renderer";
import {TemplateManager} from "./builder/template-manager";
import {parallel, series, TaskFunction, watch as _watch} from 'gulp';
import {Assets, Reset} from "./builder/tasks/basic-tasks";
import {CSS} from "./builder/tasks/css";
import {Search} from "./builder/tasks/search";
import {Articles} from "./builder/tasks/articles";
import {FeedManager} from "./builder/feed-manager";
import {Server} from "./builder/server";
import {SubBuild, SubPrepare} from "./builder/tasks/sub-build";
import {JS} from "./builder/tasks/js";
process.env.DEBUG = '*';
const env: Env = {
root: __dirname,
};
const fm = new FileManager(env.root);
const am = new ArticleManager(fm, new Renderer(config));
const tm = new TemplateManager(fm, config);
const xm = new FeedManager(fm, config);
const init = async () => {
await Promise.all([am.load(), tm.load()]);
};
const reset = new Reset(fm);
const assets = new Assets(fm);
const css = new CSS(fm, tm);
const js = new JS(fm);
const search = new Search(fm, am);
const articles = new Articles(tm, am, xm, fm);
const subBuild = new SubBuild(fm);
const subPrepare = new SubPrepare(fm);
const buildPart = [
init,
reset.run.bind(reset),
assets.run.bind(assets),
parallel(
css.run.bind(css),
js.run.bind(js),
),
parallel(
tm.renderErrorPages.bind(tm),
tm.renderDataLessPages.bind(tm),
search.run.bind(search),
articles.run.bind(articles),
)
];
export const build = series(
...buildPart,
subBuild.run.bind(subBuild),
);
export const watch = series(
build,
async (): Promise<void> => {
config.blog.debug = true;
const server = new Server(
Number.parseInt(process.env.PORT || '3000', 10),
process.env.HOST || '127.0.0.1',
'public'
);
server.run();
const andReload = (before: TaskFunction) => series(init, before, server.broadcastRefresh.bind(server));
_watch('site/templates/**/*', andReload(series(
parallel(
css.run.bind(css),
js.run.bind(js),
),
parallel(
tm.renderDataLessPages.bind(tm),
search.run.bind(search),
articles.run.bind(articles),
),
)));
_watch('site/assets/*', andReload(assets.run.bind(assets)));
_watch('site/css/*.css', andReload(series(
parallel(
css.run.bind(css),
js.run.bind(js),
),
parallel(
tm.renderDataLessPages.bind(tm),
search.run.bind(search),
articles.run.bind(articles),
),
)));
_watch('articles/*.md', andReload(parallel(
search.run.bind(search),
articles.run.bind(articles),
)));
},
);
// This task is meant to prepare a working version of artemix.org for webapp development,
// including stylesheets, index databases, and such.
export const prepareForDev = series(
...buildPart,
subPrepare.run.bind(subPrepare),
);
export default build;

16
model.sql

@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS credentials (
id INTEGER PRIMARY KEY AUTOINCREMENT,
create_time DATETIME NOT NULL,
identifier VARCHAR(50) NOT NULL,
key VARCHAR(255) NOT NULL,
description TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS feedback (
id INTEGER PRIMARY KEY AUTOINCREMENT,
submit_time DATETIME NOT NULL,
feedback TEXT NOT NULL,
app_version TEXT,
user_id TEXT,
get_back_email TEXT
);

51
package.json

@ -1,51 +0,0 @@
{
"name": "artemix.org",
"version": "1.0.0",
"description": "my blog",
"repository": "git@gitlab.com:Artemix/artemix.org",
"author": "Diane <diane@artemix.org>",
"license": "Apache 2.0",
"private": true,
"dependencies": {
"@babel/core": "^7.7.7",
"babel-preset-minify": "^0.5.1",
"debug": "^4.1.1",
"ejs": "^2.7.1",
"fs-extra": "^8.1.0",
"gray-matter": "^4.0.2",
"gulp": "^4.0.2",
"highlight.js": "^9.16.2",
"lunr": "^2.3.8",
"marked": "^0.7.0",
"rss": "^1.2.2",
"serve-handler": "^6.1.2",
"slug": "^1.1.0",
"ts-node": "^8.5.4",
"typescript": "^3.7.3",
"uglifycss": "^0.0.29",
"ws": "^7.2.0"
},
"devDependencies": {
"@types/ejs": "^3.0.0",
"@types/fs-extra": "^8.0.1",
"@types/gulp": "^4.0.6",
"@types/highlight.js": "^9.12.3",
"@types/lunr": "^2.3.2",
"@types/marked": "^0.7.2",
"@types/node": "^12.12.17",
"@types/serve-handler": "^6.1.0",
"@types/slug": "^0.9.1",
"@types/uglifycss": "^0.0.5",
"@types/ws": "^6.0.4",
"@types/babel__core": "^7.1.3",
"@types/debug": "^4.1.5",
"@types/rss": "^0.0.28"
},
"scripts": {
"build": "gulp",
"watch": "gulp watch",
"prepareForDev": "gulp prepareForDev",
"prod": "yarn && yarn build"
},
"type": "module"
}

4
public/.htaccess

@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

12
public/index.php

@ -0,0 +1,12 @@
<?php
defined('ROOT') || define('ROOT', realpath(dirname(__DIR__)));
require_once(ROOT . '/vendor/autoload.php');
use App\Runner;
$config = require_once(ROOT . '/config.php');
$routes = require_once(ROOT . '/routes.php');
(new Runner($config))->run($routes);

0
site/assets/keybase.txt → public/keybase.txt

20
routes.php

@ -0,0 +1,20 @@
<?php
return [
// data-less
[
'methods' => ['GET'],
'path' => '/about.html'
],
// data-ful
[
'methods' => ['GET'],
'path' => '/',
'action' => 'Home'
],
[
'methods' => ['GET'],
'path' => '/blog/{slug}.{mode}',
'action' => 'Article\\Show'
]
];

31
site/assets/gpg/2018-11-26/artemix@artemix.org.pubkey.asc

@ -1,31 +0,0 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFv8MWIBCADPR7vowYAgy5Po2JvJ5GjpxVdaq5bKDN2nIHZlrDZNtmI0Y/QV
olQAOVd2Tw0RXhzlyOy/2N/sVnAVdyUqWoTYMjHpiLaxtAHz/USYHqBwIOJqVhNd
pNUc7M7uFc2lQhLPXa/TGFscMguc+E+tBDMWmuYPFnT4g3ZYv1AgvpAJUkk9Pq7v
trQpR9Q7jH8Y/L1Yq3Nk3QlcLiOrdEgMComhtStvprVHuHmR3nR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MBF2oM+hW4G37PmTjBYNkqWIfR+EiKM1WrFbdu2LLsX
oygan2ViCuMJKE/23VIhaFC91YFMQrxdvrgedpr7rUR1Ag/+eZCzu0kV3WE15TAQ
GIpHnKtcGUwn5prz0fqqHYXHYktZocU9G8o5Ccm/ibii7eteviieMONAF4MnAQ==
=/Y2F
-----END PGP PUBLIC KEY BLOCK-----

0
site/assets/gpg/2019-10-13/diane@artemix.org.pubkey.asc → site/assets/gpg/diane@artemix.org.pubkey.asc

0
site/assets/gpg/2019-10-13/diane@artemix.org.pubkey.asc.txt → site/assets/gpg/diane@artemix.org.pubkey.asc.txt

7
src/Action.php

@ -0,0 +1,7 @@
<?php
namespace App;
interface Action {
public function __invoke(?array $routeParams): void;
}

25
src/Actions/About.php

@ -0,0 +1,25 @@
<?php
namespace Actions;
use App\Action;
use App\Services\HTML;
use function Siler\Http\Response\html;
class About implements Action
{
/** @var HTML $html */
private $html;
public function __construct(HTML $html)
{
$this->html = $html;
}
public function __invoke(?array $routeParams): void
{
html($this->html->render('about.html.twig'));
}
}

52
src/Actions/Article/Show.php

@ -0,0 +1,52 @@
<?php
namespace Actions\Article;
use App\Action;
use App\Services\HTML;
use App\Services\Repositories;
use function Siler\Http\Response\html;
/**
* Class Show
*
* Shows an article, supporting HTML (standard page), txt and md (markdown-formatted with front-matter).
*
* @package Actions\Article
*/
class Show implements Action
{
const SUPPORTED_FORMATS = ['txt', 'md', 'html'];
/** @var HTML $html */
private $html;
/** @var Repositories\Article $articleRepository */
private $articleRepository;
public function __construct(HTML $html, Repositories\Article $articleRepository)
{
$this->html = $html;
$this->articleRepository = $articleRepository;
}
public function __invoke(?array $routeParams): void
{
$mode = $routeParams['mode'];
if (!in_array($mode, self::SUPPORTED_FORMATS)) {
// TODO create a service or a helper thingy to have auto error pages
html('<h1>Error: invalid format (TODO)</h1>');
}
$slug = $routeParams['slug'];
$article = $this->articleRepository->getArticle($slug);
if (!$article) {
html('<h1>Error: article not found (TODO)</h1>');
}
// TODO handle modes
html($this->html->render('article/show.html.twig'));
}
}

37
src/Runner.php

@ -0,0 +1,37 @@
<?php
namespace App;
use App\Services\Config;
use DI\Container;
use DI\ContainerBuilder;
use Siler\Route;
use function DI\create;
class Runner
{
/** @var Container $di */
private $di;
public function __construct(array $config)
{
$dib = new ContainerBuilder();
$dib->addDefinitions([
Config::class => create()->constructor($config)
]);
$this->di = $dib->build();
}
/**
* @param array $routes
*/
public function run(array $routes): void
{
$di = $this->di;
foreach ($routes as $route) {
Route\route($route['methods'], $route['path'], function($params) use ($route, $di) {
return $this->di->get('\\App\\Actions\\' . $route['action'])($params);
});
}
}
}

19
src/Services/Config.php

@ -0,0 +1,19 @@
<?php
namespace App\Services;
class Config
{
/** @var array $config */
private $config;
public function __construct(array $config)
{
$this->config = $config;
}
public function getConfig(): array
{
return $this->config;
}
}

25
src/Services/Database.php

@ -0,0 +1,25 @@
<?php
namespace App\Services;
use PDO;
class Database
{
/** @var PDO $pdo */
private $pdo;
public function __construct(Config $config)
{
$db = $config->getConfig()['db'];
$this->pdo = new PDO($db['dsn'], $db['username'], $db['password'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
}
public function getConnection(): PDO
{
return $this->pdo;
}
}

23
src/Services/HTML.php

@ -0,0 +1,23 @@
<?php
namespace App\Services;
use Twig\Environment as Twig;
use Twig\Loader\FilesystemLoader;
class HTML
{
/** @var Twig $twig */
private $twig;
public function __construct(Config $config)
{
$loader = new FilesystemLoader($config->getConfig()['templates']);
$this->twig = new Twig($loader);
}
public function render(string $template, $data = []): string
{
return $this->twig->render($template, $data);
}
}

31
src/Services/Repositories/Article.php

@ -0,0 +1,31 @@
<?php
namespace App\Services\Repositories;
use App\Services\Database;
use PDO;
class Article
{
/** @var PDO $db */
private $db;
public function __construct(Database $database)
{
$this->db = $database->getConnection();
}
/**
* Get an article based on its slug
* @param string $slug the article's slug
* @return array|null an article, if found. If not found, returns the absolute value `null`
*/
public function getArticle(string $slug): ?array
{
$stmt = $this->db->prepare('SELECT * FROM article WHERE slug = ?');
$stmt->execute([$slug]);
$article = $stmt->fetch(PDO::FETCH_ASSOC);
return $article !== false ? $article : null;
}
}

82
templates/about.html.twig

@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
{% include 'fragments/head.html.twig' %}
<title>About - {{ metadata['author'] }}</title>
</head>
<body id="top">
<main>
<header class="mono">
<p class="up mono">
<a href="/">Artemis</a>
| <a href="/blog/">Blog</a>
| <a href="/portfolio.html">Portfolio</a>
| <a href="/about.html">About &amp; Contact</a>
</p>
<% if (!(typeof disableSearch !== 'undefined' && disableSearch)) { %>
<aside>
<form action="/search.html" id="search" method="get">
<input id="searchbar" name="q"
placeholder="Search an article.. (press S to select)"
/>
<button type="submit">Search</button>
</form>
</aside>
<% } %>
</header>
<article>
<h2>Hey, I'm Diane, also known as Artemis</h2>
<p>
I'm a french developer, mainly interested in backend and system development, system administration, security
and privacy.<br/>
My blog is a place on which I share both serious technical papers I've written on different subjects, but
also some rants around general subjects that're bugging me.
</p>
<p>
Nowadays, when I'm not starting yet another project that I'll never bother finishing, I'm probably reading
some books, playing some guitar, or continuing to learn
photography in the woods around my home.
</p>
<hr>
<h2>Reach out to me</h2>
<p>
If you want to contact me, you can do so <a href="mailto:reach@artemix.org">by e-mail</a> (as I'm available
on no social media platform).
You may also reach out through <a href="https://keybase.io/artemix" target="_blank"
rel="noopener">Keybase</a>.
Note that I'm not interested in any kind of advertisement or partnership, so your offers will be
ignored.<br/>
I'm a GPG user (my latest key is shown below), so you can securely reach out to
me.
</p>
{# TODO move that to DB or something like that (i.e. admin panel config) #}
<p>My current GPG key fingerprint is <code>DA53 97E2 B4A3 0E91 2694 2637 B131 53D9 2467 FCC1</code>.</p>
<pre><code>sec rsa4096 2019-10-13 [SC] [expires: 2020-10-12]
DA5397E2B4A30E9126942637B13153D92467FCC1
uid [ultimate] Diane (French back-end developer, photograph) <diane@artemix.org>
ssb rsa4096 2019-10-13 [E] [expires: 2020-10-12]</code></pre>
<hr>
<h2>About this website</h2>
<p>
This website has been made by hand, and doesn't
collect <i>anything</i> from your browsing.<br/>
{# TODO update this to match my new hosting solution, once almost in prod #}
It is currently hosted on <a href="https://www.netlify.com/" target="_blank" rel="noopener">Netlify</a>,
using its CDN, as it's fully static.<br/>
This website's source code is free (as in freedom) and open source (licensed under the Apache 2 license
terms), and can be found <a href="https://gitlab.com/Artemix/artemix.org" target="_blank" rel="noopener">here</a>.
</p>
</article>
<%- include('../partials/footer'); -%>
</main>
</body>
</html>

93
templates/base.html.twig

@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8"/>
<link rel="stylesheet" href="/style.css"/>
{# TODO re-implement PHP-based minification / cache strategy #}
{# integrity="sha384-<%= hash %>" crossorigin="anonymous"/>#}
{# TODO static resources #}
<link rel="shortcut icon" href="/a/favicon.png"/>
<link rel="apple-touch-icon" href="/a/favicon.png"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="author" content="{{ metadata['author'] }}"/>
<script src="/a/focusSearch.js" defer></script>
<title>{% block 'extra-title' %}{% endblock %} - {{ metadata['author'] }}</title>
</head>
<body id="top">
<main>
<header class="mono">
<p class="up mono">
<a href="/">Artemis</a>
| <a href="/blog/">Blog</a>
| <a href="/portfolio.html">Portfolio</a>
| <a href="/about.html">About &amp; Contact</a>
</p>
<% if (!(typeof disableSearch !== 'undefined' && disableSearch)) { %>
<aside>
<form action="/search.html" id="search" method="get">
<input id="searchbar" name="q"
placeholder="Search an article.. (press S to select)"
/>
<button type="submit">Search</button>
</form>
</aside>
<% } %>
</header>
<article>
<h2>Hey, I'm Diane, also known as Artemis</h2>
<p>
I'm a french developer, mainly interested in backend and system development, system administration, security
and privacy.<br/>
My blog is a place on which I share both serious technical papers I've written on different subjects, but
also some rants around general subjects that're bugging me.
</p>
<p>
Nowadays, when I'm not starting yet another project that I'll never bother finishing, I'm probably reading
some books, playing some guitar, or continuing to learn
photography in the woods around my home.
</p>
<hr>
<h2>Reach out to me</h2>
<p>
If you want to contact me, you can do so <a href="mailto:reach@artemix.org">by e-mail</a> (as I'm available
on no social media platform).
You may also reach out through <a href="https://keybase.io/artemix" target="_blank"
rel="noopener">Keybase</a>.
Note that I'm not interested in any kind of advertisement or partnership, so your offers will be
ignored.<br/>
I'm a GPG user (my latest key is shown below), so you can securely reach out to
me.
</p>
{# TODO move that to DB or something like that (i.e. admin panel config) #}
<p>My current GPG key fingerprint is <code>DA53 97E2 B4A3 0E91 2694 2637 B131 53D9 2467 FCC1</code>.</p>
<pre><code>sec rsa4096 2019-10-13 [SC] [expires: 2020-10-12]
DA5397E2B4A30E9126942637B13153D92467FCC1
uid [ultimate] Diane (French back-end developer, photograph) <diane@artemix.org>
ssb rsa4096 2019-10-13 [E] [expires: 2020-10-12]</code></pre>
<hr>
<h2>About this website</h2>
<p>
This website has been made by hand, and doesn't
collect <i>anything</i> from your browsing.<br/>
{# TODO update this to match my new hosting solution, once almost in prod #}
It is currently hosted on <a href="https://www.netlify.com/" target="_blank" rel="noopener">Netlify</a>,
using its CDN, as it's fully static.<br/>
This website's source code is free (as in freedom) and open source (licensed under the Apache 2 license
terms), and can be found <a href="https://gitlab.com/Artemix/artemix.org" target="_blank" rel="noopener">here</a>.
</p>
</article>
<%- include('../partials/footer'); -%>
</main>
</body>
</html>

11
templates/fragments/head.html.twig

@ -0,0 +1,11 @@
<meta charset="UTF-8"/>
<link rel="stylesheet" href="/style.css"/>
{# TODO re-implement PHP-based minification / cache strategy #}
{# integrity="sha384-<%= hash %>" crossorigin="anonymous"/>#}
{# TODO static resources #}
<link rel="shortcut icon" href="/a/favicon.png"/>
<link rel="apple-touch-icon" href="/a/favicon.png"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="author" content="{{ metadata['author'] }}"/>
<script src="/a/focusSearch.js" defer></script>

29
todo.txt

@ -0,0 +1,29 @@
add @css minification +optimisation
add @cache +optimisation
add @css underline under currently viewed page in navbar (about / folio / etc)
add home @page
add about @page
add article list @page
add portfolio @page
add article display @page
add raw / md view @page
add Atom @feed
re-scale search button to be more unified with @search bar
develop a primitive @search system
create @login page +admin
create @admin panel +admin
create @article management system +admin +cms
"can create an article" +admin +cms
"can edit an article" +admin +cms
"can edit an article's metadata" +admin +cms
"can delete an article" (flagged in DB, never really deleted) +admin +cms
find better icon for the @blog (very probably trans-themed)
"can change my GPG key online" +admin +cms +gpg
"can change my portfolio online" +admin +cms
"can change my about page online" +admin +cms
push in front the donation button in the about @page
@admin panel login notification (e-mail / sms / whatever) +notification
@admin panel repeated login fail notification (e-mail / sms / whatever) +notification
add syntaxic coloration server-side @css
give link to .asc gpg key +gpg
set right client-side @cache cookies +optimisation

16
tsconfig.json

@ -1,16 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"alwaysStrict": true,
"strictNullChecks": true,
"target": "ESNext",
"esModuleInterop": true
},
"include": [
"builder/**/*.ts"
]
}

3258
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save