Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
d739b4cfe8 | |||
6cde286d3b | |||
![]() |
7ce5ceea9e | ||
![]() |
750ae4a6cb | ||
![]() |
83d8ca71c1 | ||
![]() |
062f324783 | ||
597b13c01a | |||
be42bc7cbb | |||
5c3569eed8 | |||
36345199e3 | |||
1dd61b7596 |
4
.github/ISSUE_TEMPLATE/lighthouse.md
vendored
Normal file → Executable file
|
@ -9,5 +9,5 @@ assignees: ''
|
|||
|
||||
> Replace with description
|
||||
|
||||
Category|Score before fix|Score after fix
|
||||
--|--|--
|
||||
Device|Category|Score before fix|Score after fix
|
||||
--|--|--|--
|
||||
|
|
0
.gitignore
vendored
Normal file → Executable file
355
LICENSE
Normal file → Executable file
|
@ -1,24 +1,339 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
Preamble
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
|
|
81
README.md
Normal file → Executable file
|
@ -1,46 +1,41 @@
|
|||
<div align="center">
|
||||
<img width="100px" src="https://storage.googleapis.com/public.victorwesterlund.com/github/VictorWesterlund/victorwesterlund.com/vw.svg"/>
|
||||
<h3><strong><code>www.victorwesterlund.com</code></strong></h3>
|
||||
<p>The source code for <a href="https://victorwesterlund.com">victorwesterlund.com</a></p>
|
||||
<h3>Source code for <a href="https://victorwesterlund.com"><strong>victorwesterlund.com</strong></a></h3>
|
||||
</div>
|
||||
<h1 align="center">How to install</h1>
|
||||
<p>This guide is for Unix-based systems with NGINX, PHP 8.0 and MariaDB installed and configured.</p>
|
||||
<ol>
|
||||
<li><strong>Clone this repo.</strong><br><pre>git clone https://github.com/VictorWesterlund/victorwesterlund.com /var/www</pre></li>
|
||||
<li><strong>Expose the directory <code>/public</code> to the web.</strong><br>This can be done in multiple ways, but an <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location">NGINX <code>location</code> block</a> or symlink should do the trick.</li>
|
||||
<li><strong>Rewrite <code>api.php</code> to <code>api/*</code>.</strong><br>All requests to <code>example.com/api/*</code> should be routed to the PHP file at <code>/src/api.php</code>.<br>Just like the previous step, this can be done in multiple ways. Here is one way with an NGINX location block:<br>
|
||||
<pre>location ~ /api/* {
|
||||
try_files /src/api.php =503;
|
||||
include snippets/fastcgi-php.local.conf;
|
||||
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
|
||||
}</pre></li>
|
||||
<li><strong>Add support for the <code>.mjs</code> extension.</strong><br>NGINX doesn't have an entry for the <a href="https://jakearchibald.com/2017/es-modules-in-browsers/#mime-types">ECMAScript module <i>(<code>.mjs</code>)</i></a> file extension in its default <code>/etc/nginx/mime.types</code> file. We need to add this manually:<br>
|
||||
<pre>
|
||||
types {
|
||||
...
|
||||
application/javascript js mjs;
|
||||
...
|
||||
}
|
||||
</pre><i>PS: If you want to make your <code>Content-Type</code> <a href="https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages">WG compliant</a>, replace <code>application/javascript</code> with <code>text/javascript</code></i></li>
|
||||
<li><strong>Import the standard structure to a MariaDB database.</strong><br>A MySQL-compatible <code>.sql</code> can be <a href="https://example.com">downloaded here</a> and imported into a database with this command:<br><pre>mysql -u username -p database_name < db_structure.sql</pre>You will have to create an empty database if you don't have one already.</li>
|
||||
<li><strong>Add your MariaDB connection details to <code>/src/database/config.json</code>.</strong><br>You can add as many fallback servers as you want
|
||||
<pre lang="json">
|
||||
{
|
||||
"servers": [
|
||||
{
|
||||
"host": "db.example.com",
|
||||
"user": "mysql_user",
|
||||
"pass": "mysql_pass",
|
||||
"db": "mysql_db"
|
||||
},
|
||||
{
|
||||
"host": "fallback.db.example.com",
|
||||
"user": "mysql_user",
|
||||
"pass": "mysql_pass",
|
||||
"db": "mysql_db"
|
||||
}
|
||||
]
|
||||
}
|
||||
</pre></li>
|
||||
</ol>
|
||||
<p>That was a lot, but now we're done! Navigate to the location you exposed in step 2 and cross your fingers 🤞</p>
|
||||
|
||||
## Local installation
|
||||
|
||||
If someone for whatever reason want to set up their own environment of this. Here's how you do so assuming you have [NGINX](https://nginx.org/en/) up and running:
|
||||
|
||||
1. **Clone this repo**
|
||||
|
||||
```
|
||||
git clone https://github.com/VictorWesterlund/victorwesterlund.com
|
||||
```
|
||||
|
||||
2. **Create an NGINX site config**
|
||||
|
||||
Create and enable a new site + server config with the `root` pointed to the **/public** folder inside the repo.
|
||||
|
||||
3. **Add support for `.mjs`**
|
||||
|
||||
I'm using the hyped .mjs extension for the ES modules and NGINX does not serve the correct MIME-type for these yet.
|
||||
|
||||
Open **/etc/nginx/mime.types** with your text editor of choice and add `mjs` to the `application/javascript` MIME-type. Save and exit.
|
||||
|
||||
```
|
||||
types {
|
||||
...
|
||||
application/javascript js mjs;
|
||||
...
|
||||
}
|
||||
```
|
||||
*Psst: if you shiver at the sight of JS using another type than your HTML:s and CSS:ess (you are my kind of nerd), replace **application/javascript** with **text/javascript** and remain [WHATWG compliant](https://mimesniff.spec.whatwg.org/#javascript-mime-type)😚*
|
||||
|
||||
4. **Fire up NGINX with the new config**
|
||||
|
||||
Verify that your changes are valid and restart NGINX. Hop over to your browser and navigate to your set endpoint - fingers crossed 🤞
|
||||
```
|
||||
nginx -t
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
|
70
codeql-analysis.yml
Normal file
|
@ -0,0 +1,70 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '44 17 * * 3'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
|
@ -1,26 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Victor Westerlund - About</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Full-stack web developer from Stockholm, Sweden.">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:no-preference)">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:light)">
|
||||
<link rel="icon" href="assets/media/favicon-light.png" media="(prefers-color-scheme:dark)">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<p><a href="/">victor westerlund</a></p>
|
||||
</header>
|
||||
<main>
|
||||
<p>...</p>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="about">about</a></p>
|
||||
<p><a href="search">search</a></p>
|
||||
<p><a class="arrow" href="more">more</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -1,20 +0,0 @@
|
|||
.button {
|
||||
background-color: rgb(var(--color-contrast));
|
||||
color: rgb(var(--color-background));
|
||||
padding: var(--padding) calc(var(--padding) * 2);
|
||||
}
|
||||
|
||||
/* -- Media Queries -- */
|
||||
|
||||
@media (pointer: fine) {
|
||||
.button {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
.button:hover {
|
||||
background-color: rgba(var(--color-contrast),.11);
|
||||
color: rgb(var(--color-contrast));
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
main {
|
||||
align-self: start;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
}
|
||||
|
||||
#search {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
color: rgb(var(--color-background));
|
||||
background-color: rgb(var(--color-contrast));
|
||||
}
|
||||
|
||||
input[type="search"] {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 18px;
|
||||
color: inherit;
|
||||
padding: 0 calc(var(--padding) * 1.5);
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input[type="search"]::selection {
|
||||
color: rgb(var(--color-contrast));
|
||||
background-color: rgb(var(--color-background));
|
||||
}
|
||||
|
||||
input[type="search"]::placeholder {
|
||||
color: rgba(var(--color-background),.4);
|
||||
}
|
||||
|
||||
input[type="search"]::-webkit-search-cancel-button {
|
||||
-webkit-appearance: none;
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
background: center no-repeat rgba(var(--color-background),.1) url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAAAXNSR0IArs4c6QAAAFRJREFUeNrlkrkNADEIBK8JunD/GVW4oLnMAViagNBkLDsS3/d4sEiiqUGy7kACmyj2DeQRavEgTRGkZ4oUuyPF7ojYBRi35ENP1+qHG7+GP9/b8QPsDLZNvX0megAAAABJRU5ErkJggg==');
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#results {
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
padding: 0 var(--padding);
|
||||
}
|
||||
|
||||
/* -- Media Queries -- */
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#search {
|
||||
color: rgb(var(--color-contrast));
|
||||
background-color: rgba(var(--color-contrast),.15);
|
||||
}
|
||||
|
||||
input[type="search"]::placeholder {
|
||||
color: rgba(var(--color-contrast),.4);
|
||||
}
|
||||
}
|
219
public/assets/css/style.css
Normal file → Executable file
|
@ -1,23 +1,22 @@
|
|||
:root {
|
||||
--color-background: 255,255,255;
|
||||
--color-contrast: 33,33,33;
|
||||
--color-base: 0, 0, 0;
|
||||
--color-contrast: 256, 256, 256;
|
||||
|
||||
--padding: 20px;
|
||||
--running-height: 100px;
|
||||
--footer-denom: 1;
|
||||
--padding: clamp(40px, 2vw, 2vw);
|
||||
--border-size: clamp(4px, .25vw, .25vw);
|
||||
}
|
||||
|
||||
/* -- Cornerstones -- */
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
font-family: "Monaco","Consolas",monospace,sans-serif;
|
||||
font-family: "Monaco", "Consolas", monospace, sans-serif;
|
||||
color: rgb(var(--color-contrast));
|
||||
}
|
||||
|
||||
*::selection {
|
||||
background-color: rgb(var(--color-contrast));
|
||||
color: rgb(var(--color-background));
|
||||
color: rgb(var(--color-base));
|
||||
}
|
||||
|
||||
html,
|
||||
|
@ -27,116 +26,180 @@ body {
|
|||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
display: grid;
|
||||
grid-template-rows: var(--running-height) 1fr calc(var(--running-height) / var(--footer-denom));
|
||||
background-color: rgb(var(--color-background));
|
||||
place-items: center;
|
||||
justify-items: center;
|
||||
font-size: 21px;
|
||||
html {
|
||||
background-color: rgba(var(--color-base), .7);
|
||||
background-size: cover;
|
||||
background-blend-mode: overlay;
|
||||
background-position: center;
|
||||
background-attachment: fixed;
|
||||
}
|
||||
|
||||
body > * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
p,
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a {
|
||||
picture {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: clamp(45px, 7vw, 6vh);
|
||||
}
|
||||
|
||||
p, a {
|
||||
font-size: clamp(20px, 3vw, 2vh);
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
/* -- Components -- */
|
||||
|
||||
main {
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--padding,30px);
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
gap: var(--padding, 30px);
|
||||
}
|
||||
|
||||
.arrow {
|
||||
display: inline;
|
||||
font-weight: bold;
|
||||
body > div {
|
||||
padding: calc(var(--padding) / 2);
|
||||
}
|
||||
|
||||
.arrow::after {
|
||||
content: " →";
|
||||
:is(#intro, #card) a {
|
||||
--padding-vert: clamp(17px, 1.1vw, 1.1vw);
|
||||
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
background-color: rgba(var(--color-contrast), .13);
|
||||
backdrop-filter: blur(2px);
|
||||
-webkit-backdrop-filter: blur(2px);
|
||||
box-shadow:
|
||||
inset 0 .3vh 1.6vh rgba(0, 0, 0, 0),
|
||||
0 .1vh .3vh rgba(0, 0, 0, .12),
|
||||
0 .1vh .2vh rgba(0, 0, 0, .24);
|
||||
}
|
||||
|
||||
footer {
|
||||
justify-self: end;
|
||||
padding: 0 calc(var(--running-height) / (var(--footer-denom) * 2));
|
||||
/* --- */
|
||||
|
||||
#intro {
|
||||
padding: calc(var(--padding) / 2);
|
||||
}
|
||||
|
||||
footer p:not(:last-child) {
|
||||
display: none;
|
||||
#intro a {
|
||||
padding: var(--padding-vert) 2vw;
|
||||
border-radius: 100px;
|
||||
border: solid var(--border-size) rgba(var(--color-contrast), 0);
|
||||
margin: var(--padding) 0;
|
||||
width: calc(100% - ((var(--padding) / 2) + var(--border-size)));
|
||||
}
|
||||
|
||||
#intro p {
|
||||
margin: 1vh 0;
|
||||
font-size: clamp(20px, 3vw, 3vh);
|
||||
}
|
||||
|
||||
/* --- */
|
||||
|
||||
#card,
|
||||
#card > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: calc(var(--padding) / 2);
|
||||
}
|
||||
|
||||
#card {
|
||||
--portrait-size: clamp(128px, 12vw, 12vh);
|
||||
|
||||
position: relative;
|
||||
max-width: 600px;
|
||||
padding: var(--padding);
|
||||
border-radius: clamp(18px, 1vw, 1vw);
|
||||
backdrop-filter: saturate(100) brightness(.4);
|
||||
-webkit-backdrop-filter: saturate(100) brightness(.4);
|
||||
border: solid var(--border-size) rgba(var(--color-contrast), .1);
|
||||
box-shadow: 0 1vh 2vh rgba(0, 0, 0, .19), 0 6px 6px rgba(0, 0, 0, .23);
|
||||
}
|
||||
|
||||
#card img {
|
||||
width: var(--portrait-size);
|
||||
height: var(--portrait-size);
|
||||
position: absolute;
|
||||
border-radius: 100%;
|
||||
top: calc(((var(--portrait-size) / 2) + var(--border-size)) * -1);
|
||||
background-color: rgb(var(--color-base));
|
||||
box-shadow: 0 1vh 2vh rgba(0, 0, 0 , .19), 0 6px 6px rgba(0, 0, 0 , .23);
|
||||
}
|
||||
|
||||
#card a {
|
||||
width: 100%;
|
||||
padding: var(--padding-vert) 0;
|
||||
margin-top: calc(var(--padding) / 2);
|
||||
border-radius: clamp(9px, .5vw, .5vw);
|
||||
}
|
||||
|
||||
/* -- Media Queries -- */
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-background: 0,0,0;
|
||||
--color-contrast: 255,255,255;
|
||||
@supports ((not ((backdrop-filter: saturate(1)) and (backdrop-filter: brightness(1)))) and (not ((-webkit-backdrop-filter: saturate(1)) and (-webkit-backdrop-filter: brightness(1))))) {
|
||||
#card {
|
||||
background-color: rgba(var(--color-base), .7);
|
||||
}
|
||||
}
|
||||
|
||||
@media (pointer: fine) {
|
||||
a:hover {
|
||||
background: rgba(var(--color-contrast),.1);
|
||||
:is(#intro, #card) a {
|
||||
--transition-speed: 200ms;
|
||||
transition:
|
||||
var(--transition-speed) background-color,
|
||||
var(--transition-speed) box-shadow,
|
||||
var(--transition-speed) border-color;
|
||||
}
|
||||
|
||||
:is(#intro, #card) a:hover {
|
||||
background-color: rgba(var(--color-contrast), .2);
|
||||
border-color: rgba(var(--color-contrast), .2);
|
||||
box-shadow:
|
||||
inset 0 .3vh 1.6vh rgba(0, 0, 0, .16),
|
||||
0 .3vh .6vh rgba(0, 0, 0, .16),
|
||||
0 .3vh .6vh rgba(0, 0, 0, .23);
|
||||
}
|
||||
|
||||
:is(#intro, #card) a:active {
|
||||
background-color: rgba(var(--color-contrast), .15);
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
.arrow::after {
|
||||
content: ": " attr(href);
|
||||
@media (max-width: 330px) {
|
||||
p, a {
|
||||
text-align: left;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
#card {
|
||||
padding: calc(var(--padding) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 300px) {
|
||||
body > * {
|
||||
justify-self: center;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-aspect-ratio: 14/9) and (min-height: 500px) {
|
||||
:root {
|
||||
--footer-denom: 2;
|
||||
@media (min-aspect-ratio: 14/9) and (min-height: 600px) {
|
||||
body {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: unset;
|
||||
}
|
||||
|
||||
footer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
gap: calc(var(--padding) * 1.5);
|
||||
font-size: 19px;
|
||||
color: rgb(var(--color-background));
|
||||
background-color: rgb(var(--color-contrast));
|
||||
display: flex;
|
||||
body > div {
|
||||
display: grid;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
footer p:not(:last-child) {
|
||||
display: initial;
|
||||
body > div:last-of-type {
|
||||
padding: calc(var(--padding) * 2);
|
||||
}
|
||||
|
||||
footer p:last-child {
|
||||
margin-left: auto;
|
||||
#intro a {
|
||||
width: unset;
|
||||
}
|
||||
|
||||
footer p:first-child:last-child {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-aspect-ratio: 14/9) and (min-height: 500px) and (prefers-color-scheme: dark) {
|
||||
footer {
|
||||
color: rgb(var(--color-contrast));
|
||||
background-color: rgba(var(--color-contrast),.15);
|
||||
#card {
|
||||
min-width: 300px;
|
||||
max-width: 30vw;
|
||||
}
|
||||
}
|
||||
|
|
79
public/assets/js/glitch/Generator.mjs
Normal file
|
@ -0,0 +1,79 @@
|
|||
// Fetch and create glitchy background effects
|
||||
class Generator {
|
||||
constructor() {
|
||||
this.bg = {
|
||||
_this: this,
|
||||
_image: null,
|
||||
_dir: location,
|
||||
_dir_rel: "assets/media/b64/",
|
||||
count: 4,
|
||||
// Get or set current background
|
||||
get current () { return this._image; },
|
||||
set current (image) {
|
||||
this._image = image;
|
||||
this._this.setBg(image);
|
||||
},
|
||||
// Get or set the path to where base64 images are stored
|
||||
get dir () { return this._dir; },
|
||||
set dir (newPath) {
|
||||
const url = new URL(newPath);
|
||||
|
||||
// Replace pathname of this file with relative path to assets
|
||||
const path = url.pathname.split("/");
|
||||
path[path.length - 1] = this._dir_rel;
|
||||
|
||||
url.pathname = path.join("/");
|
||||
this._dir = url.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Genrate random int in range
|
||||
static randInt(min, max) {
|
||||
if(min === max) return min;
|
||||
return Math.round(Math.random() * (max - min) + min);
|
||||
}
|
||||
|
||||
// Generate random string of length from charset
|
||||
static randStr(length = 2) {
|
||||
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let output = "";
|
||||
for(let i = 0; i < length; i++) {
|
||||
output += charset.charAt(Math.floor(Math.random() * charset.length));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
// Give generated background image to parent thread
|
||||
setBg(image) {
|
||||
if(typeof image !== "string") throw new TypeError("Image must be of type 'string'");
|
||||
postMessage(["BG_UPDATE", image]);
|
||||
}
|
||||
|
||||
// Generate and set a glitchy image
|
||||
glitch() {
|
||||
if(!this.bg.current) return;
|
||||
const image = this.bg.current.replaceAll(Generator.randStr(), Generator.randStr());
|
||||
this.setBg(image);
|
||||
}
|
||||
|
||||
// Fetch a base64 encoded background image
|
||||
async fetchBg(id) {
|
||||
const url = new URL(this.bg.dir);
|
||||
|
||||
url.pathname += id + ".txt";
|
||||
|
||||
const image = await fetch(url);
|
||||
if(!image.ok) throw new Error("Failed to fetch background image");
|
||||
|
||||
return image.text();
|
||||
}
|
||||
|
||||
// Load a random background from the image set
|
||||
async randBg() {
|
||||
const id = Generator.randInt(1, this.bg.count);
|
||||
|
||||
const image = await this.fetchBg(id);
|
||||
this.bg.current = image;
|
||||
}
|
||||
}
|
41
public/assets/js/glitch/Glitch.mjs
Normal file
|
@ -0,0 +1,41 @@
|
|||
export default class Glitch {
|
||||
constructor(target) {
|
||||
this.worker = new Worker(this.getWorkerScriptURL());
|
||||
this.worker.addEventListener("message", event => this.message(event));
|
||||
|
||||
this.target = target ? target : document.body;
|
||||
}
|
||||
|
||||
// Update the target CSS background with an image URL
|
||||
setVisibleBg(image) {
|
||||
this.target.style.setProperty("background-image", `url(${image})`);
|
||||
}
|
||||
|
||||
// Get URL for the dedicated worker
|
||||
getWorkerScriptURL() {
|
||||
const name = "GlitchWorker.js";
|
||||
const url = new URL(import.meta.url);
|
||||
|
||||
// Replace pathname of this file with worker
|
||||
const path = url.pathname.split("/");
|
||||
path[path.length - 1] = name;
|
||||
|
||||
url.pathname = path.join("/");
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
// Event handler for messages from worker thread
|
||||
message(event) {
|
||||
const data = typeof event.data === "object" ? event.data : [event.data];
|
||||
|
||||
switch(data[0]) {
|
||||
case "READY":
|
||||
this.worker.postMessage(["START", new URL(location).toString()]);
|
||||
break;
|
||||
|
||||
case "BG_UPDATE":
|
||||
this.setVisibleBg(data[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
54
public/assets/js/glitch/GlitchWorker.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
importScripts("./Generator.mjs");
|
||||
|
||||
class GlitchWorker extends Generator {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// Delay between these values
|
||||
this.config = {
|
||||
glitch: { min: 500, max: 2500 },
|
||||
randBg: { min: 5000, max: 5000 }
|
||||
}
|
||||
|
||||
this._timers = {};
|
||||
|
||||
self.addEventListener("message", event => this.message(event));
|
||||
self.postMessage("READY");
|
||||
}
|
||||
|
||||
// Run a scoped function on a random interval between
|
||||
queue(func) {
|
||||
clearTimeout(this._timers[func]);
|
||||
const next = Generator.randInt(this.config[func].min, this.config[func].max);
|
||||
this._timers[func] = setTimeout(() => this.queue(func), next);
|
||||
|
||||
this[func]?.();
|
||||
}
|
||||
|
||||
// Set background by id and stop randBg animation
|
||||
async forceBg(id) {
|
||||
clearTimeout(this._timers.randBg);
|
||||
|
||||
const image = await this.fetchBg(id);
|
||||
this.bg.current = image;
|
||||
|
||||
this.setBg(image);
|
||||
}
|
||||
|
||||
// Event handler for messages from parent thread
|
||||
message(event) {
|
||||
const data = typeof event.data === "object" ? event.data : [event.data];
|
||||
|
||||
switch(data[0]) {
|
||||
case "START":
|
||||
this.bg.dir = data[1];
|
||||
this.randBg();
|
||||
for(const func of Object.keys(this.config)) {
|
||||
this.queue(func);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.glitch = new GlitchWorker();
|
|
@ -1,96 +0,0 @@
|
|||
export default class Search {
|
||||
constructor(input,results) {
|
||||
const self = this;
|
||||
|
||||
this.endpoint = new URL("api/search",window.location.href);
|
||||
|
||||
this.lastQuery = "";
|
||||
this.throttle = null;
|
||||
this.controller = null; // AbortController will be assigned here
|
||||
|
||||
this.results = results;
|
||||
this.input = input;
|
||||
this.input?.addEventListener("keyup",event => this.keyEvent(event)) ?? false;
|
||||
}
|
||||
|
||||
// Destroy the result DOM tree
|
||||
clearResults() {
|
||||
while(this.results.firstChild) {
|
||||
this.results.removeChild(this.results.lastChild);
|
||||
}
|
||||
}
|
||||
|
||||
// Display output as HTML
|
||||
output(html) {
|
||||
this.clearResults();
|
||||
if(typeof html === "string") {
|
||||
this.results.insertAdjacentHTML("beforeEnd",html);
|
||||
return;
|
||||
}
|
||||
this.results.appendChild(html);
|
||||
}
|
||||
|
||||
// Display a status message in a paragraph
|
||||
status(text,classList = false) {
|
||||
const element = document.createElement("p");
|
||||
if(classList !== false) {
|
||||
element.classList = classList;
|
||||
}
|
||||
|
||||
element.innerText = text;
|
||||
this.output(element);
|
||||
}
|
||||
|
||||
// Fetch search results from endpoint
|
||||
async search(query) {
|
||||
const url = new URL(this.endpoint);
|
||||
url.searchParams.set("q",query);
|
||||
|
||||
const timeout = new Promise(reject => setTimeout(() => reject("Request timed out"),3000));
|
||||
// Fetch response from server
|
||||
const api = fetch(url,{
|
||||
signal: this.controller.signal,
|
||||
headers: {
|
||||
"Content-Type": "text/html"
|
||||
}
|
||||
});
|
||||
|
||||
const result = Promise.race([api,timeout]);
|
||||
result.then(response => {
|
||||
if(!response.ok) {
|
||||
this.status("oh no, something went wrong","error");
|
||||
throw new Error("Invalid response from server");
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(html => this.output(html))
|
||||
.catch(error => {});
|
||||
}
|
||||
|
||||
// Wait until the user stops typing for a few miliseconds
|
||||
queue(query) {
|
||||
clearTimeout(this.throttle);
|
||||
this.controller = new AbortController(); // Spawn a new AbortController for each fetch
|
||||
this.throttle = setTimeout(() => this.search(query),500);
|
||||
}
|
||||
|
||||
keyEvent(event) {
|
||||
const query = event.target.value;
|
||||
// Don't do the search thing if query is too weak
|
||||
if(query.length < 1) {
|
||||
this.controller.abort(); // Abort queued search
|
||||
this.lastQuery = "";
|
||||
this.status("search results will appear here as you type");
|
||||
return;
|
||||
}
|
||||
|
||||
// Pressing a modifier key (Ctrl, Shift etc.) doesn't change the query
|
||||
if(query === this.lastQuery) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.lastQuery = query;
|
||||
this.status("searching..");
|
||||
this.queue(query);
|
||||
}
|
||||
}
|
0
public/assets/js/noscript.js
Normal file → Executable file
14
public/assets/js/script.mjs
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { default as Glitch } from "./glitch/Glitch.mjs";
|
||||
|
||||
const logging = "https://victorwesterlund-logging-dnzfgzf6za-lz.a.run.app";
|
||||
|
||||
// Log link clicks
|
||||
for(let link of document.getElementsByTagName("a")) {
|
||||
link.addEventListener("click", event => {
|
||||
event.preventDefault();
|
||||
navigator?.sendBeacon(logging, event);
|
||||
window.location.href = event.target.href;
|
||||
});
|
||||
}
|
||||
|
||||
window.glitch = new Glitch(document.body.parentElement);
|
|
@ -1,9 +0,0 @@
|
|||
import { default as Search } from "./modules/Search.mjs";
|
||||
|
||||
const searchBox = document.getElementById("search")?.getElementsByTagName("input")[0] ?? false;
|
||||
const resultsContainer = document.getElementById("results");
|
||||
|
||||
new Search(searchBox,resultsContainer);
|
||||
|
||||
// Set focus on searchbox when typing from anywhere
|
||||
window.addEventListener("keydown",() => searchBox.focus());
|
1
public/assets/media/b64/1.txt
Normal file
1
public/assets/media/b64/2.txt
Normal file
1
public/assets/media/b64/3.txt
Normal file
1
public/assets/media/b64/4.txt
Normal file
BIN
public/assets/media/banner.jpg
Normal file
After Width: | Height: | Size: 91 KiB |
0
public/assets/media/favicon-dark.png
Normal file → Executable file
Before Width: | Height: | Size: 628 B After Width: | Height: | Size: 628 B |
0
public/assets/media/favicon-light.png
Normal file → Executable file
Before Width: | Height: | Size: 638 B After Width: | Height: | Size: 638 B |
BIN
public/assets/media/pfp/128.jpg
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
public/assets/media/pfp/128.webp
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
public/assets/media/pfp/256.jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
public/assets/media/pfp/256.webp
Normal file
After Width: | Height: | Size: 4.2 KiB |
1
public/assets/media/signature.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="81.968" height="45.389"><path d="M1.172 9.641c5.062.216 7.335 9.392 8.326 13.13 1.116 4.363 1.748 8.825 2.814 13.2.833 3.43 2.456 12.139 7.651 8.584 6-4.1 8.326-13.779 10.182-20.265a119.035 119.035 0 0 0 3.014-13.471c.425-2.573 1.815-6.794.466-9.158-2.614-4.646-6.86 1.665-7.285 4.438-1.232 8.218 2.1 18.317 5.22 25.727.733 1.74 1.773 5.828 4.1 6.369s3.9-2.173 4.712-3.822a29.121 29.121 0 0 0 1.782-5.3c.325-1.174.741-5 1.865-5.6 2.623-1.349 3.115 6.469 3.264 7.443.275 1.807.491 3.971 1.6 5.5 4.687 6.494 10.108-8.717 11.306-11.331C64.5 15.661 71.425 8.343 81.134 4.438c1.474-.591.833-3.014-.667-2.406-11.606 4.679-18.575 13.229-23.595 24.394a56.539 56.539 0 0 1-2.5 5.1 6.551 6.551 0 0 1-1.1 1.8 2.66 2.66 0 0 1-3.081-.241c-.916-1.041-.691-4.279-.916-5.712a16.236 16.236 0 0 0-1.141-4.488c-1.54-3.2-4.754-3.4-6.511-.266-1.315 2.34-1.665 5.2-2.431 7.718-.375 1.191-1.4 5.362-3.455 4.654-1.207-.416-2.539-5.67-2.9-6.661a69.05 69.05 0 0 1-2.914-10.182c-.7-3.38-2.09-8.409-1.066-11.881.316-1.082 1.99-4.163 2.681-2.29a5.7 5.7 0 0 1-.2 1.973c-.25 2.173-.608 4.338-1.007 6.494Q29.3 18.1 27.723 23.646a95.743 95.743 0 0 1-3.28 9.791c-.949 2.331-6.128 12.822-8.25 7.044-2.5-6.752-2.906-14.062-5-20.914-1.482-4.812-4.08-12.147-9.991-12.4C-.4 7.1-.4 9.6 1.206 9.666Z" fill="#fff"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
|
@ -1,26 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Victor Westerlund - Contact</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Full-stack web developer from Stockholm, Sweden.">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:no-preference)">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:light)">
|
||||
<link rel="icon" href="assets/media/favicon-light.png" media="(prefers-color-scheme:dark)">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<p><a href="/">victor westerlund</a></p>
|
||||
</header>
|
||||
<main>
|
||||
<p>hello@​victorwesterlund.com</p>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="about">about</a></p>
|
||||
<p><a href="search">search</a></p>
|
||||
<p><a class="arrow" href="more">more</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
35
public/error.html
Normal file → Executable file
|
@ -5,33 +5,24 @@
|
|||
<title>Victor Westerlund</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Full-stack web developer from Stockholm, Sweden.">
|
||||
<meta name="theme-color" content="#000000">
|
||||
<meta property='og:title' content='Victor Westerlund'>
|
||||
<meta property='og:image' content='//victorwesterlund.com/assets/media/banner.jpg'>
|
||||
<meta property='og:description' content='Full-stack web developer from Stockholm, Sweden.'>
|
||||
<meta property='og:url' content='https://victorwesterlund.com'>
|
||||
<link rel="icon" href="/assets/media/favicon-dark.png" media="(prefers-color-scheme:no-preference)">
|
||||
<link rel="icon" href="/assets/media/favicon-dark.png" media="(prefers-color-scheme:light)">
|
||||
<link rel="icon" href="/assets/media/favicon-light.png" media="(prefers-color-scheme:dark)">
|
||||
<link rel="stylesheet" href="/assets/css/style.css">
|
||||
<link rel="stylesheet" href="/assets/css/components.css">
|
||||
<style>
|
||||
main { align-items: center; gap: unset; }
|
||||
h1 { font-size: clamp(25px,40px,3vw); }
|
||||
.button { margin-top: calc(var(--padding) * 2); }
|
||||
footer { background-color: transparent; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<p><a href="/">victor westerlund</a></p>
|
||||
</header>
|
||||
<main>
|
||||
<h1>there is nothing here</h1>
|
||||
<p>and that is all I know</p>
|
||||
<a href="/">
|
||||
<div class="button">
|
||||
<p>take me home</p>
|
||||
</div>
|
||||
</a>
|
||||
</main>
|
||||
<footer>
|
||||
<p>404 not found</p>
|
||||
</footer>
|
||||
<div>
|
||||
<div id="intro">
|
||||
<h1>there is nothing here</h1>
|
||||
<p>and that's all I know</p>
|
||||
<a href="/">take me home -></a>
|
||||
</div>
|
||||
</div>
|
||||
<script type="module" src="/assets/js/script.mjs"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
1
public/humans.txt
Normal file
|
@ -0,0 +1 @@
|
|||
This website was designed and built by me (Victor Westerlund) in 2022 using code and ☕
|
54
public/index.html
Normal file → Executable file
|
@ -5,22 +5,54 @@
|
|||
<title>Victor Westerlund</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Full-stack web developer from Stockholm, Sweden.">
|
||||
<meta name="theme-color" content="#000000">
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2RKGE84YP9"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'G-2RKGE84YP9');
|
||||
</script>
|
||||
<meta property='og:title' content='Victor Westerlund'>
|
||||
<meta property='og:image' content='//victorwesterlund.com/assets/media/banner.jpg'>
|
||||
<meta property='og:description' content='Full-stack web developer from Stockholm, Sweden.'>
|
||||
<meta property='og:url' content='https://victorwesterlund.com'>
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:no-preference)">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:light)">
|
||||
<link rel="icon" href="assets/media/favicon-light.png" media="(prefers-color-scheme:dark)">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
<style>body { grid-template-rows: 1fr calc(var(--running-height) / var(--footer-denom)); }</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<p>victor westerlund</p>
|
||||
<p><a class="arrow" href="https://github.com/VictorWesterlund">github</a></p>
|
||||
<p><a class="arrow" href="contact">contact</a></p>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="about">about</a></p>
|
||||
<p><a href="search">search</a></p>
|
||||
<p><a class="arrow" href="more">more</a></p>
|
||||
</footer>
|
||||
<div>
|
||||
<div id="intro">
|
||||
<p>hello, my name is</p>
|
||||
<h1>victor</h1>
|
||||
<p>I'm a</p>
|
||||
<h1>full-stack</h1>
|
||||
<h1>developer</h1>
|
||||
<p>from Sweden</p>
|
||||
<a href="https://github.com/VictorWesterlund">my github -></a>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div id="card">
|
||||
<picture>
|
||||
<source srcset="assets/media/pfp/256.webp" type="image/webp" media="(min-width: 600px)">
|
||||
<source srcset="assets/media/pfp/128.webp" type="image/webp">
|
||||
<source srcset="assets/media/pfp/256.jpg" type="image/jpg" media="(min-width: 600px)">
|
||||
<img src="assets/media/pfp/128.jpg" alt="portrait of victor"/>
|
||||
</picture>
|
||||
<div>
|
||||
<p>I create things with code. When I'm not creating things with code, I enjoy skiing, watching movies and some occasional gaming</p>
|
||||
<p>And beyond computer science, I'm also an armchair rabbit-holer for engineering, physics and astronomy</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>...and ☕, full-time</p>
|
||||
</div>
|
||||
<!--<a href="contact">contact me</a>-->
|
||||
</div>
|
||||
</div>
|
||||
<script type="module" src="assets/js/script.mjs"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Victor Westerlund</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Full-stack web developer from Stockholm, Sweden.">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:no-preference)">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:light)">
|
||||
<link rel="icon" href="assets/media/favicon-light.png" media="(prefers-color-scheme:dark)">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
<style>
|
||||
.arrow[href="/"]::after { content: ""; }
|
||||
.arrow[href="/"]::before { content: "← "; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<p><a href="/">victor westerlund</a></p>
|
||||
</header>
|
||||
<main>
|
||||
<p><a class="arrow" href="https://github.com/VictorWesterlund">github</a></p>
|
||||
<p><a class="arrow" href="contact">contact</a></p>
|
||||
<p><a class="arrow" href="about">about</a></p>
|
||||
<p></p>
|
||||
<p>random stuff <span style="white-space:nowrap;">--</span></p>
|
||||
<p><a class="arrow" href="search">search</a></p>
|
||||
<p><a class="arrow" rel="noopener" target="_blank" href="https://open.spotify.com/playlist/1NiR19Fg3AHg0XlqJhEKTF?si=c53d53f4c11f4971">megalodon</a></p>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="about">about</a></p>
|
||||
<p><a href="search">search</a></p>
|
||||
<p><a class="arrow" href="/">less</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
0
public/robots.txt
Normal file → Executable file
|
@ -1,35 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Victor Westerlund - Search</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Full-stack web developer from Stockholm, Sweden.">
|
||||
<meta name="google" content="nositelinkssearchbox">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:no-preference)">
|
||||
<link rel="icon" href="assets/media/favicon-dark.png" media="(prefers-color-scheme:light)">
|
||||
<link rel="icon" href="assets/media/favicon-light.png" media="(prefers-color-scheme:dark)">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
<link rel="stylesheet" href="assets/css/search.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<p><a href="/">victor westerlund</a></p>
|
||||
</header>
|
||||
<main>
|
||||
<div id="search">
|
||||
<input type="search" spellcheck="false" autocomplete="false" placeholder="start typing to search..">
|
||||
</div>
|
||||
<div id="results">
|
||||
<p>search results will appear here as you type</p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="about">about</a></p>
|
||||
<p><a href="search">search</a></p>
|
||||
<p><a class="arrow" href="more">more</a></p>
|
||||
</footer>
|
||||
<script type="module" src="assets/js/search.mjs"></script>
|
||||
<script nomodule defer src="assets/js/noscript.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
||||
<url>
|
||||
<loc>https://victorwesterlund.com/</loc>
|
||||
<lastmod>2021-02-09T06:54:02+00:00</lastmod>
|
||||
</url>
|
||||
</urlset>
|
50
src/api.php
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
class APIRouter {
|
||||
public function __construct($path) {
|
||||
// List of implemented API services
|
||||
$this->services = [
|
||||
"search" => function() {
|
||||
require_once "/search/Search.php";
|
||||
new Search();
|
||||
}
|
||||
];
|
||||
|
||||
$this->url = parse_url($path);
|
||||
$this->run();
|
||||
}
|
||||
|
||||
// Find the requested service by looking at the next URI breadcrumb after "api"
|
||||
private function get_service() {
|
||||
$path = explode("/",$this->url["path"]);
|
||||
|
||||
$service = array_search("api",$path) + 1; // Next array value
|
||||
$service = $path[$service];
|
||||
return $service;
|
||||
}
|
||||
|
||||
private function error($message,$code = 500) {
|
||||
$output = [
|
||||
"ok" => false,
|
||||
"code" => strval($code),
|
||||
"message" => $message
|
||||
];
|
||||
|
||||
header("Content-Type: application/json");
|
||||
http_response_code($code);
|
||||
echo json_encode($output);
|
||||
}
|
||||
|
||||
// Run the requested service if it exists in services list
|
||||
private function run() {
|
||||
$service = $this->get_service();
|
||||
if(!array_key_exists($service,$this->services)) {
|
||||
$this->error("Inavlid API");
|
||||
return false;
|
||||
}
|
||||
// Import and run requested service
|
||||
$this->services[$service]();
|
||||
}
|
||||
}
|
||||
|
||||
new APIRouter($_SERVER["REQUEST_URI"]);
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Import {
|
||||
// Import assets from disk
|
||||
public static function file($file) {
|
||||
$content = file_get_contents($file);
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Import JSON to PHP list
|
||||
public static function json($file) {
|
||||
$contents = Import::file($file);
|
||||
$json = json_decode($contents);
|
||||
return $json;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
include_once dirname(__DIR__,1)."/core/Import.php";
|
||||
|
||||
class Database extends mysqli {
|
||||
public function __construct($table) {
|
||||
// Load config file from this directory
|
||||
$config_path = dirname(__FILE__,1)."/config.json";
|
||||
$config = Import::json($config_path);
|
||||
|
||||
parent::__construct();
|
||||
//$this->ssl_set();
|
||||
|
||||
// Attempt to connect to MySQL servers in order (moving to the next on failure)
|
||||
foreach($config->servers as $server) {
|
||||
$db = $this->real_connect($server->host,$server->user,$server->pass,$server->db);
|
||||
if($db) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Exit with error code
|
||||
private function error($message) {
|
||||
http_response_code(500);
|
||||
header("Content-Type: application/json");
|
||||
$output = json_encode([
|
||||
"error" => $message
|
||||
]);
|
||||
die($output);
|
||||
}
|
||||
|
||||
// Return affected rows as an array of arrays
|
||||
protected function get_rows($sql) {
|
||||
if(!$this->ping()) {
|
||||
$this->error("No database connected");
|
||||
}
|
||||
|
||||
$query = $this->query($sql);
|
||||
|
||||
$rows = [];
|
||||
while($row = $query->fetch_row()) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"servers": [
|
||||
{
|
||||
"host": "",
|
||||
"user": "",
|
||||
"pass": "",
|
||||
"db": ""
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once dirname(__DIR__,1)."/core/Import.php";
|
||||
require_once dirname(__DIR__,1)."/database/Database.php";
|
||||
|
||||
class Search extends Database {
|
||||
public function __construct() {
|
||||
parent::__construct("search");
|
||||
|
||||
$this->query = $this->real_escape_string($_GET["q"]); // Escape the user-provided query
|
||||
|
||||
// Determine response type from request header or search param
|
||||
$mime_type = $_SERVER["HTTP_CONTENT_TYPE"] ? $_SERVER["HTTP_CONTENT_TYPE"] : $_GET["f"];
|
||||
switch($mime_type) {
|
||||
case "html":
|
||||
case "text/html":
|
||||
$this->get_html();
|
||||
break;
|
||||
|
||||
default:
|
||||
case "json":
|
||||
case "application/json":
|
||||
$this->get_json();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform a seach on the given query and return the results as an array
|
||||
private function get_results() {
|
||||
$sql = "SELECT template,title,content,href FROM `search` WHERE `title` LIKE '%{$this->query}%' OR `content` LIKE '%{$this->query}%'";
|
||||
$rows = $this->get_rows($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// Load HTML template from disk
|
||||
private function get_html_template($name) {
|
||||
$path = dirname(__FILE__,1)."/templates/${name}.html";
|
||||
if(!is_file($path)) {
|
||||
return $this->get_html_template("card_error_display");
|
||||
}
|
||||
$html = Import::file($path);
|
||||
return $html;
|
||||
}
|
||||
|
||||
// Return query as HTML from templates
|
||||
private function get_html() {
|
||||
$results = $this->get_results();
|
||||
|
||||
if(count($results) < 1) {
|
||||
$results[] = ["message","info","no results 😞"];
|
||||
}
|
||||
|
||||
// Load HTML and format each response from template
|
||||
$results = array_map(function($result) {
|
||||
// Use first row as template name
|
||||
$template = $this->get_html_template($result[0]);
|
||||
// Use remaining rows as format arguments
|
||||
$format = array_shift($result);
|
||||
return sprintf($template,...$result);
|
||||
},$results);
|
||||
|
||||
header("Content-Type: text/html");
|
||||
echo implode("",$results);
|
||||
}
|
||||
|
||||
// Return query as JSON
|
||||
private function get_json() {
|
||||
$results = $this->get_results();
|
||||
$data = [
|
||||
"results" => []
|
||||
];
|
||||
|
||||
// Assign custom keys to each value (not db columns)
|
||||
foreach($results as $result) {
|
||||
$data["results"][] = [
|
||||
"html_template" => $result[0],
|
||||
"title" => $result[1],
|
||||
"content" => $result[2],
|
||||
"href" => $result[3]
|
||||
];
|
||||
}
|
||||
|
||||
$json = json_encode($data);
|
||||
header("Content-Type: application/json");
|
||||
echo $json;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<div class="card">
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M3 2.75A2.75 2.75 0 0 1 5.75 0h14.5a.75.75 0 0 1 .75.75v20.5a.75.75 0 0 1-.75.75h-6a.75.75 0 0 1 0-1.5h5.25v-4H6A1.5 1.5 0 0 0 4.5 18v.75c0 .716.43 1.334 1.05 1.605a.75.75 0 0 1-.6 1.374A3.25 3.25 0 0 1 3 18.75v-16zM19.5 1.5V15H6c-.546 0-1.059.146-1.5.401V2.75c0-.69.56-1.25 1.25-1.25H19.5z" fill="currentColor"/><path d="M7 18.25a.25.25 0 0 1 .25-.25h5a.25.25 0 0 1 .25.25v5.01a.25.25 0 0 1-.397.201l-2.206-1.604a.25.25 0 0 0-.294 0L7.397 23.46a.25.25 0 0 1-.397-.2v-5.01z" fill="currentColor"/></svg>
|
||||
<p>%s</p>
|
||||
</div>
|
||||
<p>%s</p>
|
||||
<p href="%s" class="button">read more</p>
|
||||
</div>
|
|
@ -1,4 +0,0 @@
|
|||
<div class="card error">
|
||||
<p><strong>There was a problem displaying this result</strong></p>
|
||||
<p>This is a problem on my side, sorry about that</p>
|
||||
</div>
|
|
@ -1,8 +0,0 @@
|
|||
<div class="card">
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M3 2.75A2.75 2.75 0 0 1 5.75 0h14.5a.75.75 0 0 1 .75.75v20.5a.75.75 0 0 1-.75.75h-6a.75.75 0 0 1 0-1.5h5.25v-4H6A1.5 1.5 0 0 0 4.5 18v.75c0 .716.43 1.334 1.05 1.605a.75.75 0 0 1-.6 1.374A3.25 3.25 0 0 1 3 18.75v-16zM19.5 1.5V15H6c-.546 0-1.059.146-1.5.401V2.75c0-.69.56-1.25 1.25-1.25H19.5z" fill="currentColor"/><path d="M7 18.25a.25.25 0 0 1 .25-.25h5a.25.25 0 0 1 .25.25v5.01a.25.25 0 0 1-.397.201l-2.206-1.604a.25.25 0 0 0-.294 0L7.397 23.46a.25.25 0 0 1-.397-.2v-5.01z" fill="currentColor"/></svg>
|
||||
<p>%s</p>
|
||||
</div>
|
||||
<p>%s</p>
|
||||
<p href="%s" class="button">read more</p>
|
||||
</div>
|
|
@ -1 +0,0 @@
|
|||
<p class="%s">%s</p>
|
|
@ -1,5 +0,0 @@
|
|||
<div class="resultsFooter">
|
||||
<svg id="previous"><polygon points="40,10 0,20 40,30"/></svg>
|
||||
<p>showing %s/%s results<span> (query took %s seconds)</span></p>
|
||||
<svg id="next"><polygon points="0,10 40,20 0,30"/></svg>
|
||||
</div>
|