Compare commits
4 commits
88aa5b27d7
...
f33dc130b8
Author | SHA1 | Date | |
---|---|---|---|
f33dc130b8 | |||
ee44847974 | |||
8f2f8c3ff2 | |||
261aab9a4b |
98 changed files with 800 additions and 5629 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
|
@ -1,7 +0,0 @@
|
||||||
**/atri.dad
|
|
||||||
**/.env
|
|
||||||
**/airbin
|
|
||||||
**/tmp
|
|
||||||
**/*.rdb
|
|
||||||
fly.toml
|
|
||||||
tailwind.config.*.js
|
|
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -1,2 +0,0 @@
|
||||||
*.css linguist-vendored
|
|
||||||
*.js linguist-vendored
|
|
18
.gitignore
vendored
18
.gitignore
vendored
|
@ -1,9 +1,11 @@
|
||||||
atri.dad
|
# dotenv environment variable files
|
||||||
main
|
|
||||||
.env
|
.env
|
||||||
airbin
|
.env.development.local
|
||||||
tmp/
|
.env.test.local
|
||||||
*.rdb
|
.env.production.local
|
||||||
.DS_Store
|
.env.local
|
||||||
tailwind.config.js
|
|
||||||
lib/stylegen/tw
|
# Fresh build directory
|
||||||
|
_fresh/
|
||||||
|
# npm dependencies
|
||||||
|
node_modules/
|
||||||
|
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"deno.enable": true
|
||||||
|
}
|
51
Dockerfile
51
Dockerfile
|
@ -1,43 +1,30 @@
|
||||||
FROM --platform=$BUILDPLATFORM golang:1.24.0-alpine AS builder
|
FROM denoland/deno:alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Download dependencies and install required tools
|
COPY deno.json import_map.json ./
|
||||||
COPY go.mod go.sum ./
|
COPY dev.ts main.ts .env* ./
|
||||||
RUN go mod download && \
|
|
||||||
go install github.com/swaggo/swag/cmd/swag@latest
|
|
||||||
|
|
||||||
# Copy source code and Makefile
|
COPY components/ ./components/
|
||||||
COPY . .
|
COPY islands/ ./islands/
|
||||||
|
COPY lib/ ./lib/
|
||||||
|
COPY posts/ ./posts/
|
||||||
|
COPY routes/ ./routes/
|
||||||
|
COPY static/ ./static/
|
||||||
|
COPY utils/ ./utils/
|
||||||
|
|
||||||
# Install required tools and make scripts executable
|
RUN deno cache main.ts
|
||||||
RUN apk add --no-cache upx make bash
|
|
||||||
|
|
||||||
# Create necessary directories
|
FROM denoland/deno:alpine
|
||||||
RUN mkdir -p /app/public/css
|
|
||||||
|
|
||||||
# Generate assets and build with optimizations
|
WORKDIR /app
|
||||||
SHELL ["/bin/bash", "-c"]
|
|
||||||
|
|
||||||
# Platform-specific builds
|
COPY --from=builder /deno-dir/ /deno-dir/
|
||||||
ARG TARGETPLATFORM
|
COPY --from=builder /app/ /app/
|
||||||
RUN cd /app && make generate && \
|
|
||||||
case "${TARGETPLATFORM}" in \
|
|
||||||
"linux/amd64") GOARCH=amd64 ;; \
|
|
||||||
"linux/arm64") GOARCH=arm64 ;; \
|
|
||||||
*) GOARCH=amd64 ;; \
|
|
||||||
esac && \
|
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build \
|
|
||||||
-ldflags='-s -w -extldflags "-static"' \
|
|
||||||
-tags netgo,osusergo \
|
|
||||||
-o /go/bin/app
|
|
||||||
|
|
||||||
# Final stage
|
ENV DENO_DEPLOYMENT=production
|
||||||
FROM --platform=$TARGETPLATFORM scratch
|
|
||||||
|
|
||||||
# Copy static files and assets
|
EXPOSE 8000
|
||||||
COPY --from=builder /app/public/css/styles.css /public/css/styles.css
|
|
||||||
COPY --from=builder /app/docs /docs
|
|
||||||
COPY --from=builder /go/bin/app /app
|
|
||||||
|
|
||||||
ENTRYPOINT ["/app"]
|
# Run the server
|
||||||
|
CMD ["run", "-A", "main.ts"]
|
||||||
|
|
232
LICENSE
232
LICENSE
|
@ -1,232 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
|
||||||
|
|
||||||
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 them 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 prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. 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.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
“This License” refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
|
||||||
|
|
||||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
|
||||||
|
|
||||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
|
||||||
|
|
||||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
|
||||||
|
|
||||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
|
||||||
|
|
||||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
You may convey 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; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
|
||||||
|
|
||||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
|
||||||
|
|
||||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
|
||||||
|
|
||||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
|
||||||
|
|
||||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
If 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 convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of the GNU 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 that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
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.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 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.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
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 state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
gpl
|
|
||||||
Copyright (C) 2025 atridad
|
|
||||||
|
|
||||||
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 3 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, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
gpl Copyright (C) 2025 atridad
|
|
||||||
This program 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, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU 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. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
105
Makefile
105
Makefile
|
@ -1,105 +0,0 @@
|
||||||
# Emoji
|
|
||||||
CHECK := ✅
|
|
||||||
BUILD := 🔨
|
|
||||||
CLEAN := 🧹
|
|
||||||
RUN := 🚀
|
|
||||||
TEST := 🧪
|
|
||||||
DOCKER := 🐳
|
|
||||||
WARN := ⚠️
|
|
||||||
DOCS := 📚
|
|
||||||
|
|
||||||
# Variables
|
|
||||||
BINARY_NAME := atri.dad
|
|
||||||
DOCKER_IMAGE := atri-dot-dad
|
|
||||||
GO_FILES := $(wildcard *.go)
|
|
||||||
|
|
||||||
# Docker detection
|
|
||||||
DOCKER_ENV := $(shell if [ -f /.dockerenv ]; then echo true; else echo false; fi)
|
|
||||||
ifeq ($(DOCKER_ENV),true)
|
|
||||||
BASE_PATH := /app
|
|
||||||
else
|
|
||||||
BASE_PATH := $(CURDIR)
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: all build clean run dev docker-dev docker-build docker-run test help reset ensure-swag
|
|
||||||
|
|
||||||
help:
|
|
||||||
@echo "Available commands:"
|
|
||||||
@echo "make reset - Clean and reset the project to initial state"
|
|
||||||
@echo "make build - Generate docs and build Go binary"
|
|
||||||
@echo "make run - Build and run the binary"
|
|
||||||
@echo "make dev - Run in development mode"
|
|
||||||
@echo "make docker-dev - Run development environment in Docker"
|
|
||||||
@echo "make docker-run - Run production container"
|
|
||||||
@echo "make test - Run tests"
|
|
||||||
@echo "make prod - Full production build"
|
|
||||||
|
|
||||||
# Check if swag is installed
|
|
||||||
ensure-swag:
|
|
||||||
@command -v swag >/dev/null 2>&1 || { \
|
|
||||||
echo "$(WARN) Swagger CLI (swag) is not installed. Installing..."; \
|
|
||||||
go install github.com/swaggo/swag/cmd/swag@latest; \
|
|
||||||
}
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@echo "$(CLEAN) Cleaning project..."
|
|
||||||
@rm -f $(BINARY_NAME)
|
|
||||||
@rm -rf docs/docs.go docs/swagger.json docs/swagger.yaml
|
|
||||||
@go clean -cache -testcache -modcache
|
|
||||||
@echo "$(CHECK) Project clean complete"
|
|
||||||
|
|
||||||
swaggergen: ensure-swag
|
|
||||||
@echo "$(DOCS) Generating Swagger documentation..."
|
|
||||||
@swag init
|
|
||||||
@echo "$(CHECK) Swagger docs generated"
|
|
||||||
|
|
||||||
# Combined generation target
|
|
||||||
generate: swaggergen
|
|
||||||
|
|
||||||
build: generate
|
|
||||||
@echo "$(BUILD) Building binary..."
|
|
||||||
@go build -o $(BINARY_NAME)
|
|
||||||
@echo "$(CHECK) Build complete: $(BINARY_NAME)"
|
|
||||||
|
|
||||||
test:
|
|
||||||
@echo "$(TEST) Running tests..."
|
|
||||||
@go test ./...
|
|
||||||
@echo "$(CHECK) Tests complete"
|
|
||||||
|
|
||||||
dev: generate
|
|
||||||
@echo "$(RUN) Starting development server..."
|
|
||||||
@go run main.go
|
|
||||||
|
|
||||||
run: build
|
|
||||||
@echo "$(RUN) Running server..."
|
|
||||||
@./$(BINARY_NAME)
|
|
||||||
|
|
||||||
docker-dev:
|
|
||||||
@echo "$(DOCKER) Starting development container..."
|
|
||||||
@docker-compose -f docker-compose.dev.yml up --build
|
|
||||||
|
|
||||||
docker-build: generate
|
|
||||||
@echo "$(DOCKER) Building production Docker image..."
|
|
||||||
@docker build -t $(DOCKER_IMAGE) .
|
|
||||||
@echo "$(CHECK) Docker image build complete"
|
|
||||||
|
|
||||||
docker-run: docker-build
|
|
||||||
@echo "$(DOCKER) Running production container..."
|
|
||||||
@docker-compose up
|
|
||||||
|
|
||||||
deps:
|
|
||||||
@echo "$(BUILD) Installing dependencies..."
|
|
||||||
@go mod download
|
|
||||||
@go install github.com/swaggo/swag/cmd/swag@latest
|
|
||||||
@echo "$(CHECK) Dependencies installed"
|
|
||||||
|
|
||||||
fmt:
|
|
||||||
@echo "$(BUILD) Formatting code..."
|
|
||||||
@go fmt ./...
|
|
||||||
@echo "$(CHECK) Code formatting complete"
|
|
||||||
|
|
||||||
# Full production build
|
|
||||||
prod: clean generate build
|
|
||||||
@echo "$(CHECK) Production build complete"
|
|
||||||
|
|
||||||
.DEFAULT_GOAL := help
|
|
29
README.md
29
README.md
|
@ -1,21 +1,16 @@
|
||||||
# atri.dad
|
# Fresh project
|
||||||
This is my personal website!
|
|
||||||
|
|
||||||
## Stack:
|
Your new Fresh project is ready to go. You can follow the Fresh "Getting
|
||||||
- Backend: Golang + Echo
|
Started" guide here: https://fresh.deno.dev/docs/getting-started
|
||||||
- Rendering: Golang templates
|
|
||||||
- Style: TailwindCSS + DaisyUI
|
|
||||||
- Content format: Markdown
|
|
||||||
|
|
||||||
## Requirements:
|
### Usage
|
||||||
- Golang 1.23.1
|
|
||||||
|
|
||||||
## Getting Started
|
Make sure to install Deno: https://deno.land/manual/getting_started/installation
|
||||||
1. Clone this repository
|
|
||||||
2. Copy `.env.example` to `.env`
|
|
||||||
3. Run `go mod download`
|
|
||||||
4. Start the server: `go run main.go`
|
|
||||||
|
|
||||||
## API Documentation
|
Then start the project:
|
||||||
1. Install swag by running ```go install github.com/swaggo/swag/cmd/swag@latest```
|
|
||||||
2. Visit `/api/swagger/index.html` after starting the server
|
```
|
||||||
|
deno task start
|
||||||
|
```
|
||||||
|
|
||||||
|
This will watch the project directory and restart as necessary.
|
||||||
|
|
19
api/ping.go
19
api/ping.go
|
@ -1,19 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ping godoc
|
|
||||||
// @Summary Ping the server
|
|
||||||
// @Description Get a pong response
|
|
||||||
// @Tags ping
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Success 200 {string} string "Pong!"
|
|
||||||
// @Router /ping [get]
|
|
||||||
func Ping(c echo.Context) error {
|
|
||||||
return c.String(http.StatusOK, "Pong!")
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PostCopy godoc
|
|
||||||
// @Summary Get copy icon SVG
|
|
||||||
// @Description Returns an SVG of a copy icon
|
|
||||||
// @Tags post
|
|
||||||
// @Accept json
|
|
||||||
// @Produce html
|
|
||||||
// @Success 200 {string} string "SVG content"
|
|
||||||
// @Router /post/copy [get]
|
|
||||||
func PostCopy(c echo.Context) error {
|
|
||||||
return c.String(http.StatusOK, `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`)
|
|
||||||
}
|
|
63
api/rss.go
63
api/rss.go
|
@ -1,63 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
// RSSFeedHandler godoc
|
|
||||||
// @Summary Get RSS feed
|
|
||||||
// @Description Returns an RSS feed of blog posts
|
|
||||||
// @Tags rss
|
|
||||||
// @Accept json
|
|
||||||
// @Produce xml
|
|
||||||
// @Success 200 {string} string "RSS feed content"
|
|
||||||
// @Failure 500 {string} string "Internal Server Error"
|
|
||||||
// @Router /rss [get]
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
contentfs "atri.dad/content"
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/gorilla/feeds"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RSSFeedHandler(c echo.Context) error {
|
|
||||||
files, err := fs.ReadDir(contentfs.FS, ".")
|
|
||||||
|
|
||||||
protocol := "http"
|
|
||||||
if c.Request().TLS != nil {
|
|
||||||
protocol = "https"
|
|
||||||
}
|
|
||||||
|
|
||||||
feed := &feeds.Feed{
|
|
||||||
Title: "Atridad Lahiji's Blog",
|
|
||||||
Link: &feeds.Link{Href: protocol + "://" + c.Request().Host + "/api/rss"},
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if !file.IsDir() && strings.HasSuffix(file.Name(), ".md") {
|
|
||||||
|
|
||||||
frontMatter, err := lib.ExtractFrontMatter(file, contentfs.FS)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(c.Response().Writer, "There was an issue rendering the posts!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
date, _ := time.Parse("January 2 2006", frontMatter.Date)
|
|
||||||
|
|
||||||
feed.Add(&feeds.Item{
|
|
||||||
Title: frontMatter.Name,
|
|
||||||
Link: &feeds.Link{Href: protocol + "://" + c.Request().Host + "/post/" + strings.TrimSuffix(file.Name(), ".md")},
|
|
||||||
Created: date,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rss, _ := feed.ToRss()
|
|
||||||
return c.Blob(http.StatusOK, "application/rss+xml", []byte(rss))
|
|
||||||
}
|
|
83
api/sse.go
83
api/sse.go
|
@ -1,83 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SSE godoc
|
|
||||||
// @Summary Server-Sent Events endpoint
|
|
||||||
// @Description Establishes a Server-Sent Events connection
|
|
||||||
// @Tags sse
|
|
||||||
// @Accept json
|
|
||||||
// @Produce text/event-stream
|
|
||||||
// @Param channel query string false "Channel name"
|
|
||||||
// @Success 200 {string} string "Event stream"
|
|
||||||
// @Router /sse [get]
|
|
||||||
func SSE(c echo.Context) error {
|
|
||||||
channel := c.QueryParam("channel")
|
|
||||||
if channel == "" {
|
|
||||||
channel = "default"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the request context, which is cancelled when the client disconnects
|
|
||||||
ctx := c.Request().Context()
|
|
||||||
|
|
||||||
// Standard SSE headers
|
|
||||||
c.Response().Header().Set("Content-Type", "text/event-stream")
|
|
||||||
c.Response().Header().Set("Cache-Control", "no-cache")
|
|
||||||
c.Response().Header().Set("Connection", "keep-alive")
|
|
||||||
c.Response().Header().Set("X-Accel-Buffering", "no")
|
|
||||||
|
|
||||||
// CORS headers
|
|
||||||
origin := c.Request().Header.Get("Origin")
|
|
||||||
if origin == "https://atri.dad" || origin == "http://localhost:3000" {
|
|
||||||
c.Response().Header().Set("Access-Control-Allow-Origin", origin)
|
|
||||||
} else {
|
|
||||||
c.Response().Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare the response
|
|
||||||
c.Response().WriteHeader(http.StatusOK)
|
|
||||||
c.Response().Flush()
|
|
||||||
|
|
||||||
// Client channel for SSE messages
|
|
||||||
clientChan := make(chan string)
|
|
||||||
lib.SSEServer.AddClient(channel, clientChan)
|
|
||||||
defer lib.SSEServer.RemoveClient(channel, clientChan)
|
|
||||||
|
|
||||||
// Write initial message
|
|
||||||
if _, err := c.Response().Write([]byte("data: Connected to SSE server\n\n")); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Response().Flush()
|
|
||||||
|
|
||||||
// Keep-alive ticker
|
|
||||||
ticker := time.NewTicker(15 * time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
// Event loop
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil
|
|
||||||
case <-ticker.C:
|
|
||||||
// Send keep-alive comment
|
|
||||||
if _, err := c.Response().Write([]byte(": ping\n\n")); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Response().Flush()
|
|
||||||
case msg := <-clientChan:
|
|
||||||
// Format as standard SSE message
|
|
||||||
data := fmt.Sprintf("data: %s\n\n", msg)
|
|
||||||
if _, err := c.Response().Write([]byte(data)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.Response().Flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ResizeHandler godoc
|
|
||||||
// @Summary Resize an image
|
|
||||||
// @Description Resizes an uploaded image to specified dimensions
|
|
||||||
// @Tags tools
|
|
||||||
// @Accept mpfd
|
|
||||||
// @Produce png
|
|
||||||
// @Param image formData file true "Image file to resize"
|
|
||||||
// @Param width formData int true "Target width"
|
|
||||||
// @Param height formData int true "Target height"
|
|
||||||
// @Success 200 {file} binary "Resized image"
|
|
||||||
// @Failure 400 {string} string "Bad request"
|
|
||||||
// @Failure 500 {string} string "Internal server error"
|
|
||||||
// @Router /tools/resize [post]
|
|
||||||
func ResizeHandler(c echo.Context) error {
|
|
||||||
|
|
||||||
// Extract file from request
|
|
||||||
file, _, err := c.Request().FormFile("image")
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusBadRequest, "Error getting image file")
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
// Get dimensions from form data parameters
|
|
||||||
widthStr := c.FormValue("width")
|
|
||||||
heightStr := c.FormValue("height")
|
|
||||||
|
|
||||||
// Validate and convert dimensions to integers
|
|
||||||
width, err := strconv.Atoi(widthStr)
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusBadRequest, "Invalid width parameter")
|
|
||||||
}
|
|
||||||
|
|
||||||
height, err := strconv.Atoi(heightStr)
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusBadRequest, "Invalid height parameter")
|
|
||||||
}
|
|
||||||
|
|
||||||
fileBlob, err := lib.ResizeImg(file, width, height)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusInternalServerError, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Response().Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "resized.png"))
|
|
||||||
|
|
||||||
return c.Blob(http.StatusOK, "image/png", fileBlob)
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SSEDemoSend godoc
|
|
||||||
// @Summary Send SSE message
|
|
||||||
// @Description Sends a message to a specified SSE channel
|
|
||||||
// @Tags sse,tools
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Param channel query string false "Channel name"
|
|
||||||
// @Param message query string false "Message to send"
|
|
||||||
// @Success 200 {object} map[string]string
|
|
||||||
// @Failure 400 {object} map[string]string
|
|
||||||
// @Router /tools/sendsse [post]
|
|
||||||
func SSEDemoSend(c echo.Context) error {
|
|
||||||
channel := c.QueryParam("channel")
|
|
||||||
if channel == "" {
|
|
||||||
channel = "default"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get message from query parameters, form value, or request body
|
|
||||||
message := c.QueryParam("message")
|
|
||||||
if message == "" {
|
|
||||||
message = c.FormValue("message")
|
|
||||||
if message == "" {
|
|
||||||
var body map[string]string
|
|
||||||
if err := c.Bind(&body); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
message = body["message"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if message == "" {
|
|
||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "message parameter is required"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send message
|
|
||||||
lib.SSEServer.SendSSE(channel, message)
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, map[string]string{"status": "message sent"})
|
|
||||||
}
|
|
15
components/HomeButtonLinks.tsx
Normal file
15
components/HomeButtonLinks.tsx
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
export default function HomeButtonLinks() {
|
||||||
|
return (
|
||||||
|
<div class="flex flex-row gap-4 text-3xl">
|
||||||
|
<a
|
||||||
|
href="/files/Atridad_Lahiji_Resume_Public.pdf"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="React"
|
||||||
|
class="btn btn-dash btn-primary"
|
||||||
|
>
|
||||||
|
Resumé
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
37
components/PostCard.tsx
Normal file
37
components/PostCard.tsx
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import { LuArrowRight, LuClock } from "@preact-icons/lu";
|
||||||
|
import { Post } from "../lib/posts.ts";
|
||||||
|
|
||||||
|
export default function PostCard(props: { post: Post }) {
|
||||||
|
const { post } = props;
|
||||||
|
return (
|
||||||
|
<div class="card bg-accent shadow-lg w-full sm:w-[calc(50%-1rem)] md:w-96 min-w-[280px] max-w-sm shrink">
|
||||||
|
<div class="card-body p-4 sm:p-6">
|
||||||
|
<h2 class="card-title text-base-100 justify-center text-center break-words">
|
||||||
|
{post.title}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p class="text-center text-base-100 break-words">{post.blurb}</p>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center justify-center text-base-100 opacity-75 gap-2 text-sm sm:text-base">
|
||||||
|
<LuClock className="flex-shrink-0" />
|
||||||
|
<span>
|
||||||
|
{post.publishedAt!.toLocaleDateString("en-us", {
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-actions justify-end mt-4">
|
||||||
|
<a
|
||||||
|
href={`/post/${post.slug}`}
|
||||||
|
class="btn btn-circle btn-sm sm:btn-md btn-primary text-accent"
|
||||||
|
>
|
||||||
|
<LuArrowRight class="text-lg" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
37
components/ProjectCard.tsx
Normal file
37
components/ProjectCard.tsx
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import { LuLink } from "@preact-icons/lu";
|
||||||
|
|
||||||
|
interface Project {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
link: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProjectCard(props: { project: Project }) {
|
||||||
|
const { project } = props;
|
||||||
|
return (
|
||||||
|
<div class="card bg-accent shadow-lg w-full sm:w-[calc(50%-1rem)] md:w-96 min-w-[280px] max-w-sm shrink">
|
||||||
|
<div class="card-body p-6">
|
||||||
|
<h2 class="card-title text-xl md:text-2xl font-bold justify-center text-center break-words text-base-100">
|
||||||
|
{project.name}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p class="text-center break-words my-4 text-base-100">
|
||||||
|
{project.description}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="card-actions justify-end mt-4 ">
|
||||||
|
<a
|
||||||
|
href={project.link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="btn btn-circle btn-secondary text-accent"
|
||||||
|
aria-label={`Visit ${project.name}`}
|
||||||
|
>
|
||||||
|
<LuLink class="text-lg" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
44
components/SocialLinks.tsx
Normal file
44
components/SocialLinks.tsx
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import { LuMail } from "@preact-icons/lu";
|
||||||
|
import { SiBluesky, SiForgejo, SiRss } from "@preact-icons/si";
|
||||||
|
|
||||||
|
export default function SocialLinks() {
|
||||||
|
return (
|
||||||
|
<div class="flex flex-row gap-4 text-3xl">
|
||||||
|
<a
|
||||||
|
href="mailto:me@atri.dad"
|
||||||
|
aria-label="Email me"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<LuMail />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="/feed"
|
||||||
|
aria-label="RSS Feed"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiRss />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://git.atri.dad/atridad"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="Forgejo (Git)"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiForgejo />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://bsky.app/profile/atri.dad"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="Bluesky Profile"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiBluesky />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
85
components/TechLinks.tsx
Normal file
85
components/TechLinks.tsx
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
import {
|
||||||
|
SiDeno,
|
||||||
|
SiDocker,
|
||||||
|
SiGo,
|
||||||
|
SiPostgresql,
|
||||||
|
SiReact,
|
||||||
|
SiRedis,
|
||||||
|
SiTypescript,
|
||||||
|
} from "@preact-icons/si";
|
||||||
|
|
||||||
|
export default function TechLinks() {
|
||||||
|
return (
|
||||||
|
<div class="flex flex-row gap-4 text-3xl">
|
||||||
|
<a
|
||||||
|
href="https://react.dev/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="React"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiReact />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://www.typescriptlang.org/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="TypeScript"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiTypescript />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://deno.com/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="Deno"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiDeno />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://go.dev/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="Go"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiGo />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://www.postgresql.org/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="PostgreSQL"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiPostgresql />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://redis.io/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="Redis"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiRedis />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://www.docker.com/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label="Docker"
|
||||||
|
class="hover:text-primary transition-colors"
|
||||||
|
>
|
||||||
|
<SiDocker />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
package contentfs
|
|
||||||
|
|
||||||
import "embed"
|
|
||||||
|
|
||||||
//go:embed *
|
|
||||||
var FS embed.FS
|
|
|
@ -1,18 +0,0 @@
|
||||||
---
|
|
||||||
name: "Current List of Favourite Tools"
|
|
||||||
description: "A periodically updated list of tools I use day-to-day."
|
|
||||||
date: "January 28 2025"
|
|
||||||
tags: ["tools","list"]
|
|
||||||
---
|
|
||||||
I change what I use _constantly_ in order to find something that feels just right. I wanted to share them here and update them here so when someone asks, I can just point them to this article.
|
|
||||||
|
|
||||||
1. Sublime Text - Currently my favourite text editor. Fast, simple, and extensible. Just a joy to use!
|
|
||||||
2. Sublime Merge - Honestly one of the fastest and best looking git GUIs around! Awesome for visualizing changes when you have larger code changes.
|
|
||||||
3. Ghostty - A Zig based terminal emulator by one of the founders of Hashicorp. Runs great on MacOS and Linux. No windows for those who are into that.
|
|
||||||
4. OrbStack - A faster alternative to Docker Desktop that also runs VMs!
|
|
||||||
5. Bitwarden - An open-source password manager. Easy to self host with Vaultwarden and with the recent updates, it has SSH Agent support!
|
|
||||||
6. iA Writer - A minimalist Markdown editor. For MacOS and Windows only, but really the MacOS version is the most mature. Awesome for focus.
|
|
||||||
7. Dataflare - A simple but powerful cross-platform database client. Supports most common databases, including LibSQL which is rare!
|
|
||||||
8. Bruno - A simple and powerful API client, similar to Postman. An critical tool to debug API endpoints.
|
|
||||||
|
|
||||||
I hope you found this helpful! This will be periodically updated to avoid outdated recommendations.
|
|
|
@ -1,10 +0,0 @@
|
||||||
---
|
|
||||||
name: "Welcome!"
|
|
||||||
description: "Welcome to my website!"
|
|
||||||
date: "October 20 2024"
|
|
||||||
tags: ["welcome"]
|
|
||||||
---
|
|
||||||
|
|
||||||
Welcome to my site! This is a place for me to share my thoughts and updates on my projects. I hope you find something interesting here.
|
|
||||||
|
|
||||||
Feel free to reach out if you have any questions or comments. I'd love to hear from you! I can be reached by email at [me@atri.dad](mailto:me@atri.dad).
|
|
46
deno.json
Normal file
46
deno.json
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"nodeModulesDir": "auto",
|
||||||
|
"lock": false,
|
||||||
|
"tasks": {
|
||||||
|
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
|
||||||
|
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
|
||||||
|
"manifest": "deno task cli manifest $(pwd)",
|
||||||
|
"start": "deno run -A --watch=static/,routes/ dev.ts",
|
||||||
|
"build": "deno run -A dev.ts build",
|
||||||
|
"preview": "deno run -A main.ts",
|
||||||
|
"update": "deno run -A -r https://fresh.deno.dev/update ."
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"rules": {
|
||||||
|
"tags": [
|
||||||
|
"fresh",
|
||||||
|
"recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"**/_fresh/*"
|
||||||
|
],
|
||||||
|
"imports": {
|
||||||
|
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
|
||||||
|
"@deno/gfm": "jsr:@deno/gfm@^0.11.0",
|
||||||
|
"@pakornv/fresh-plugin-tailwindcss": "jsr:@pakornv/fresh-plugin-tailwindcss@^1.0.2",
|
||||||
|
"@preact-icons/lu": "jsr:@preact-icons/lu@^1.0.13",
|
||||||
|
"@preact-icons/si": "jsr:@preact-icons/si@^1.0.13",
|
||||||
|
"@std/front-matter": "jsr:@std/front-matter@^1.0.9",
|
||||||
|
"@std/path": "jsr:@std/path@^1.0.9",
|
||||||
|
"@tailwindcss/typography": "npm:@tailwindcss/typography@^0.5.16",
|
||||||
|
"daisyui": "npm:daisyui@^5.0.27",
|
||||||
|
"preact": "npm:preact@10.22.1",
|
||||||
|
"preact/jsx-runtime": "npm:preact@10.22.1/jsx-runtime",
|
||||||
|
"preact/hooks": "npm:preact@10.22.1/hooks",
|
||||||
|
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
||||||
|
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
|
||||||
|
"$std/": "https://deno.land/std@0.216.0/",
|
||||||
|
"tailwindcss": "npm:tailwindcss@^4.1.4"
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
8
dev.ts
Executable file
8
dev.ts
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||||
|
|
||||||
|
import dev from "$fresh/dev.ts";
|
||||||
|
import config from "./fresh.config.ts";
|
||||||
|
|
||||||
|
import "$std/dotenv/load.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts", config);
|
|
@ -1,10 +0,0 @@
|
||||||
services:
|
|
||||||
app:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: atridad:latest
|
|
||||||
command: ["/app"]
|
|
||||||
pull_policy: build
|
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
|
@ -1,6 +1,13 @@
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: ${IMAGE}
|
image: ${IMAGE:-ghcr.io/yourusername/your-fresh-project:latest}
|
||||||
command: ["/app"]
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
- DENO_DEPLOYMENT=production
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:8000"
|
||||||
|
# If you need to persist any data
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
222
docs/docs.go
222
docs/docs.go
|
@ -1,222 +0,0 @@
|
||||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
|
||||||
package docs
|
|
||||||
|
|
||||||
import "github.com/swaggo/swag"
|
|
||||||
|
|
||||||
const docTemplate = `{
|
|
||||||
"schemes": {{ marshal .Schemes }},
|
|
||||||
"swagger": "2.0",
|
|
||||||
"info": {
|
|
||||||
"description": "{{escape .Description}}",
|
|
||||||
"title": "{{.Title}}",
|
|
||||||
"contact": {},
|
|
||||||
"version": "{{.Version}}"
|
|
||||||
},
|
|
||||||
"host": "{{.Host}}",
|
|
||||||
"basePath": "{{.BasePath}}",
|
|
||||||
"paths": {
|
|
||||||
"/ping": {
|
|
||||||
"get": {
|
|
||||||
"description": "Get a pong response",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ping"
|
|
||||||
],
|
|
||||||
"summary": "Ping the server",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Pong!",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/post/copy": {
|
|
||||||
"get": {
|
|
||||||
"description": "Returns an SVG of a copy icon",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"text/html"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"post"
|
|
||||||
],
|
|
||||||
"summary": "Get copy icon SVG",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "SVG content",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/sse": {
|
|
||||||
"get": {
|
|
||||||
"description": "Establishes a Server-Sent Events connection",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"text/event-stream"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"sse"
|
|
||||||
],
|
|
||||||
"summary": "Server-Sent Events endpoint",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Channel name",
|
|
||||||
"name": "channel",
|
|
||||||
"in": "query"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Event stream",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/tools/resize": {
|
|
||||||
"post": {
|
|
||||||
"description": "Resizes an uploaded image to specified dimensions",
|
|
||||||
"consumes": [
|
|
||||||
"multipart/form-data"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"image/png"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"tools"
|
|
||||||
],
|
|
||||||
"summary": "Resize an image",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "file",
|
|
||||||
"description": "Image file to resize",
|
|
||||||
"name": "image",
|
|
||||||
"in": "formData",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Target width",
|
|
||||||
"name": "width",
|
|
||||||
"in": "formData",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Target height",
|
|
||||||
"name": "height",
|
|
||||||
"in": "formData",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Resized image",
|
|
||||||
"schema": {
|
|
||||||
"type": "file"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad request",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal server error",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/tools/sendsse": {
|
|
||||||
"post": {
|
|
||||||
"description": "Sends a message to a specified SSE channel",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"sse",
|
|
||||||
"tools"
|
|
||||||
],
|
|
||||||
"summary": "Send SSE message",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Channel name",
|
|
||||||
"name": "channel",
|
|
||||||
"in": "query"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Message to send",
|
|
||||||
"name": "message",
|
|
||||||
"in": "query"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "OK",
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad Request",
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
|
||||||
var SwaggerInfo = &swag.Spec{
|
|
||||||
Version: "1.0",
|
|
||||||
Host: "localhost:3000",
|
|
||||||
BasePath: "/api",
|
|
||||||
Schemes: []string{},
|
|
||||||
Title: "Atri.dad API",
|
|
||||||
Description: "This is the API for atri.dad",
|
|
||||||
InfoInstanceName: "swagger",
|
|
||||||
SwaggerTemplate: docTemplate,
|
|
||||||
LeftDelim: "{{",
|
|
||||||
RightDelim: "}}",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
|
||||||
}
|
|
|
@ -1,198 +0,0 @@
|
||||||
{
|
|
||||||
"swagger": "2.0",
|
|
||||||
"info": {
|
|
||||||
"description": "This is the API for atri.dad",
|
|
||||||
"title": "Atri.dad API",
|
|
||||||
"contact": {},
|
|
||||||
"version": "1.0"
|
|
||||||
},
|
|
||||||
"host": "localhost:3000",
|
|
||||||
"basePath": "/api",
|
|
||||||
"paths": {
|
|
||||||
"/ping": {
|
|
||||||
"get": {
|
|
||||||
"description": "Get a pong response",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"ping"
|
|
||||||
],
|
|
||||||
"summary": "Ping the server",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Pong!",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/post/copy": {
|
|
||||||
"get": {
|
|
||||||
"description": "Returns an SVG of a copy icon",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"text/html"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"post"
|
|
||||||
],
|
|
||||||
"summary": "Get copy icon SVG",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "SVG content",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/sse": {
|
|
||||||
"get": {
|
|
||||||
"description": "Establishes a Server-Sent Events connection",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"text/event-stream"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"sse"
|
|
||||||
],
|
|
||||||
"summary": "Server-Sent Events endpoint",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Channel name",
|
|
||||||
"name": "channel",
|
|
||||||
"in": "query"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Event stream",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/tools/resize": {
|
|
||||||
"post": {
|
|
||||||
"description": "Resizes an uploaded image to specified dimensions",
|
|
||||||
"consumes": [
|
|
||||||
"multipart/form-data"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"image/png"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"tools"
|
|
||||||
],
|
|
||||||
"summary": "Resize an image",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "file",
|
|
||||||
"description": "Image file to resize",
|
|
||||||
"name": "image",
|
|
||||||
"in": "formData",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Target width",
|
|
||||||
"name": "width",
|
|
||||||
"in": "formData",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Target height",
|
|
||||||
"name": "height",
|
|
||||||
"in": "formData",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Resized image",
|
|
||||||
"schema": {
|
|
||||||
"type": "file"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad request",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal server error",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/tools/sendsse": {
|
|
||||||
"post": {
|
|
||||||
"description": "Sends a message to a specified SSE channel",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"sse",
|
|
||||||
"tools"
|
|
||||||
],
|
|
||||||
"summary": "Send SSE message",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Channel name",
|
|
||||||
"name": "channel",
|
|
||||||
"in": "query"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Message to send",
|
|
||||||
"name": "message",
|
|
||||||
"in": "query"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "OK",
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad Request",
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
basePath: /api
|
|
||||||
host: localhost:3000
|
|
||||||
info:
|
|
||||||
contact: {}
|
|
||||||
description: This is the API for atri.dad
|
|
||||||
title: Atri.dad API
|
|
||||||
version: "1.0"
|
|
||||||
paths:
|
|
||||||
/ping:
|
|
||||||
get:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Get a pong response
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Pong!
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
summary: Ping the server
|
|
||||||
tags:
|
|
||||||
- ping
|
|
||||||
/post/copy:
|
|
||||||
get:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Returns an SVG of a copy icon
|
|
||||||
produces:
|
|
||||||
- text/html
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: SVG content
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
summary: Get copy icon SVG
|
|
||||||
tags:
|
|
||||||
- post
|
|
||||||
/sse:
|
|
||||||
get:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Establishes a Server-Sent Events connection
|
|
||||||
parameters:
|
|
||||||
- description: Channel name
|
|
||||||
in: query
|
|
||||||
name: channel
|
|
||||||
type: string
|
|
||||||
produces:
|
|
||||||
- text/event-stream
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Event stream
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
summary: Server-Sent Events endpoint
|
|
||||||
tags:
|
|
||||||
- sse
|
|
||||||
/tools/resize:
|
|
||||||
post:
|
|
||||||
consumes:
|
|
||||||
- multipart/form-data
|
|
||||||
description: Resizes an uploaded image to specified dimensions
|
|
||||||
parameters:
|
|
||||||
- description: Image file to resize
|
|
||||||
in: formData
|
|
||||||
name: image
|
|
||||||
required: true
|
|
||||||
type: file
|
|
||||||
- description: Target width
|
|
||||||
in: formData
|
|
||||||
name: width
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
- description: Target height
|
|
||||||
in: formData
|
|
||||||
name: height
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- image/png
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Resized image
|
|
||||||
schema:
|
|
||||||
type: file
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
summary: Resize an image
|
|
||||||
tags:
|
|
||||||
- tools
|
|
||||||
/tools/sendsse:
|
|
||||||
post:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Sends a message to a specified SSE channel
|
|
||||||
parameters:
|
|
||||||
- description: Channel name
|
|
||||||
in: query
|
|
||||||
name: channel
|
|
||||||
type: string
|
|
||||||
- description: Message to send
|
|
||||||
in: query
|
|
||||||
name: message
|
|
||||||
type: string
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
schema:
|
|
||||||
additionalProperties:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
additionalProperties:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
summary: Send SSE message
|
|
||||||
tags:
|
|
||||||
- sse
|
|
||||||
- tools
|
|
||||||
swagger: "2.0"
|
|
6
fresh.config.ts
Normal file
6
fresh.config.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { defineConfig } from "$fresh/server.ts";
|
||||||
|
import tailwind from "@pakornv/fresh-plugin-tailwindcss";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [tailwind()],
|
||||||
|
});
|
31
fresh.gen.ts
Normal file
31
fresh.gen.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// DO NOT EDIT. This file is generated by Fresh.
|
||||||
|
// This file SHOULD be checked into source version control.
|
||||||
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import * as $_404 from "./routes/_404.tsx";
|
||||||
|
import * as $_app from "./routes/_app.tsx";
|
||||||
|
import * as $_layout from "./routes/_layout.tsx";
|
||||||
|
import * as $api_joke from "./routes/api/joke.ts";
|
||||||
|
import * as $index from "./routes/index.tsx";
|
||||||
|
import * as $post_slug_ from "./routes/post/[slug].tsx";
|
||||||
|
import * as $posts from "./routes/posts.tsx";
|
||||||
|
import * as $projects from "./routes/projects.tsx";
|
||||||
|
|
||||||
|
import type { Manifest } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/_404.tsx": $_404,
|
||||||
|
"./routes/_app.tsx": $_app,
|
||||||
|
"./routes/_layout.tsx": $_layout,
|
||||||
|
"./routes/api/joke.ts": $api_joke,
|
||||||
|
"./routes/index.tsx": $index,
|
||||||
|
"./routes/post/[slug].tsx": $post_slug_,
|
||||||
|
"./routes/posts.tsx": $posts,
|
||||||
|
"./routes/projects.tsx": $projects,
|
||||||
|
},
|
||||||
|
islands: {},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
} satisfies Manifest;
|
||||||
|
|
||||||
|
export default manifest;
|
47
go.mod
47
go.mod
|
@ -1,47 +0,0 @@
|
||||||
module atri.dad
|
|
||||||
|
|
||||||
go 1.24
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/alecthomas/chroma/v2 v2.15.0
|
|
||||||
github.com/swaggo/echo-swagger v1.4.1
|
|
||||||
github.com/swaggo/swag v1.16.4
|
|
||||||
golang.org/x/image v0.25.0
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
|
||||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
|
||||||
github.com/ghodss/yaml v1.0.0 // indirect
|
|
||||||
github.com/go-openapi/jsonpointer v0.21.1 // indirect
|
|
||||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
|
||||||
github.com/go-openapi/spec v0.21.0 // indirect
|
|
||||||
github.com/go-openapi/swag v0.23.1 // indirect
|
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
|
||||||
github.com/labstack/gommon v0.4.2 // indirect
|
|
||||||
github.com/mailru/easyjson v0.9.0 // indirect
|
|
||||||
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
|
||||||
github.com/swaggo/files/v2 v2.0.2 // indirect
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
|
||||||
golang.org/x/net v0.37.0 // indirect
|
|
||||||
golang.org/x/text v0.23.0 // indirect
|
|
||||||
golang.org/x/time v0.11.0 // indirect
|
|
||||||
golang.org/x/tools v0.31.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/gookit/color v1.5.4
|
|
||||||
github.com/gorilla/feeds v1.2.0
|
|
||||||
github.com/joho/godotenv v1.5.1
|
|
||||||
github.com/labstack/echo/v4 v4.13.3
|
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
||||||
github.com/yuin/goldmark v1.7.8
|
|
||||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
|
|
||||||
golang.org/x/crypto v0.36.0 // indirect
|
|
||||||
golang.org/x/sys v0.31.0 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
|
||||||
)
|
|
105
go.sum
105
go.sum
|
@ -1,105 +0,0 @@
|
||||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
|
||||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
|
||||||
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
|
|
||||||
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
|
||||||
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
|
|
||||||
github.com/alecthomas/chroma/v2 v2.15.0 h1:LxXTQHFoYrstG2nnV9y2X5O94sOBzf0CIUpSTbpxvMc=
|
|
||||||
github.com/alecthomas/chroma/v2 v2.15.0/go.mod h1:gUhVLrPDXPtp/f+L1jo9xepo9gL4eLwRuGAunSZMkio=
|
|
||||||
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
|
|
||||||
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
|
|
||||||
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
|
||||||
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
|
||||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
|
||||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
|
||||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
|
||||||
github.com/go-openapi/jsonpointer v0.21.1 h1:whnzv/pNXtK2FbX/W9yJfRmE2gsmkfahjMKB0fZvcic=
|
|
||||||
github.com/go-openapi/jsonpointer v0.21.1/go.mod h1:50I1STOfbY1ycR8jGz8DaMeLCdXiI6aDteEdRNNzpdk=
|
|
||||||
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
|
||||||
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
|
|
||||||
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
|
|
||||||
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
|
||||||
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
|
|
||||||
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
|
|
||||||
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
|
|
||||||
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
|
|
||||||
github.com/gorilla/feeds v1.2.0 h1:O6pBiXJ5JHhPvqy53NsjKOThq+dNFm8+DFrxBEdzSCc=
|
|
||||||
github.com/gorilla/feeds v1.2.0/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
|
|
||||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
|
||||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
|
||||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|
||||||
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
|
|
||||||
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
|
|
||||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
|
||||||
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
|
||||||
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
|
|
||||||
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
|
||||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
|
||||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
|
||||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
github.com/swaggo/echo-swagger v1.4.1 h1:Yf0uPaJWp1uRtDloZALyLnvdBeoEL5Kc7DtnjzO/TUk=
|
|
||||||
github.com/swaggo/echo-swagger v1.4.1/go.mod h1:C8bSi+9yH2FLZsnhqMZLIZddpUxZdBYuNHbtaS1Hljc=
|
|
||||||
github.com/swaggo/files/v2 v2.0.2 h1:Bq4tgS/yxLB/3nwOMcul5oLEUKa877Ykgz3CJMVbQKU=
|
|
||||||
github.com/swaggo/files/v2 v2.0.2/go.mod h1:TVqetIzZsO9OhHX1Am9sRf9LdrFZqoK49N37KON/jr0=
|
|
||||||
github.com/swaggo/swag v1.16.4 h1:clWJtd9LStiG3VeijiCfOVODP6VpHtKdQy9ELFG3s1A=
|
|
||||||
github.com/swaggo/swag v1.16.4/go.mod h1:VBsHJRsDvfYvqoiMKnsdwhNV9LEMHgEDZcyVYX0sxPg=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
|
||||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
|
||||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
|
||||||
github.com/yuin/goldmark v1.4.15/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
|
||||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
|
||||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
|
||||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ=
|
|
||||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I=
|
|
||||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
|
||||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
|
||||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
|
|
||||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
|
||||||
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
|
|
||||||
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
|
|
||||||
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
|
|
||||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
|
||||||
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
|
||||||
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
|
||||||
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
|
||||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
|
||||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
|
||||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
|
||||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
|
||||||
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
|
|
||||||
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
|
||||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
|
||||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
101
lib/email.go
101
lib/email.go
|
@ -1,101 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net/smtp"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SendEmail(to_email string, from_email string, from_name string, html string, subject string) {
|
|
||||||
LogInfo.Println("Starting email sending process")
|
|
||||||
|
|
||||||
// Set up authentication information.
|
|
||||||
auth := smtp.PlainAuth(
|
|
||||||
"",
|
|
||||||
os.Getenv("SMTP_USERNAME"),
|
|
||||||
os.Getenv("SMTP_PASSWORD"),
|
|
||||||
os.Getenv("SMTP_HOST"),
|
|
||||||
)
|
|
||||||
|
|
||||||
LogSuccess.Println("Authentication set up")
|
|
||||||
|
|
||||||
// Connect to the server, authenticate, set the sender and recipient,
|
|
||||||
// and send the email all in one step.
|
|
||||||
msg := []byte("From: " + from_name + " <" + from_email + ">\r\n" +
|
|
||||||
"To: " + to_email + "\r\n" +
|
|
||||||
"Subject: " + subject + "\r\n" +
|
|
||||||
"Content-Type: text/html; charset=UTF-8" + "\r\n" +
|
|
||||||
"\r\n" +
|
|
||||||
html + "\r\n")
|
|
||||||
|
|
||||||
tlsconfig := &tls.Config{
|
|
||||||
InsecureSkipVerify: false,
|
|
||||||
ServerName: os.Getenv("SMTP_HOST"),
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("TLS configuration set up")
|
|
||||||
|
|
||||||
c, err := smtp.Dial(os.Getenv("SMTP_HOST") + ":587")
|
|
||||||
if err != nil {
|
|
||||||
LogError.Println("Error dialing SMTP server:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Connected to SMTP server")
|
|
||||||
|
|
||||||
if err = c.StartTLS(tlsconfig); err != nil {
|
|
||||||
LogError.Println("Error starting TLS:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogInfo.Println("TLS started")
|
|
||||||
|
|
||||||
if err = c.Auth(auth); err != nil {
|
|
||||||
LogError.Println("Error authenticating with SMTP server:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Authenticated with SMTP server")
|
|
||||||
|
|
||||||
if err = c.Mail(from_email); err != nil {
|
|
||||||
LogError.Println("Error setting sender address:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Sender address set")
|
|
||||||
|
|
||||||
if err = c.Rcpt(to_email); err != nil {
|
|
||||||
LogError.Println("Error setting recipient address:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Recipient address set")
|
|
||||||
|
|
||||||
w, err := c.Data()
|
|
||||||
if err != nil {
|
|
||||||
LogError.Println("Error getting write closer:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Got write closer")
|
|
||||||
|
|
||||||
_, err = w.Write(msg)
|
|
||||||
if err != nil {
|
|
||||||
LogError.Println("Error writing message:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Message written")
|
|
||||||
|
|
||||||
err = w.Close()
|
|
||||||
if err != nil {
|
|
||||||
LogError.Println("Error closing write closer:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSuccess.Println("Write closer closed")
|
|
||||||
|
|
||||||
c.Quit()
|
|
||||||
|
|
||||||
LogSuccess.Println("Email sent successfully")
|
|
||||||
}
|
|
33
lib/files.go
33
lib/files.go
|
@ -1,33 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListFiles returns a slice of file paths in the given directory
|
|
||||||
func ListFiles(dir string) ([]string, error) {
|
|
||||||
var filePaths []string
|
|
||||||
|
|
||||||
entries, err := os.ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, entry := range entries {
|
|
||||||
if entry.IsDir() {
|
|
||||||
// Recursively list files in subdirectories
|
|
||||||
subDir := filepath.Join(dir, entry.Name())
|
|
||||||
subFiles, err := ListFiles(subDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
filePaths = append(filePaths, subFiles...)
|
|
||||||
} else {
|
|
||||||
// Add file path to the slice
|
|
||||||
filePath := filepath.Join(dir, entry.Name())
|
|
||||||
filePaths = append(filePaths, filePath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filePaths, nil
|
|
||||||
}
|
|
33
lib/img.go
33
lib/img.go
|
@ -1,33 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"image/png"
|
|
||||||
"mime/multipart"
|
|
||||||
|
|
||||||
"golang.org/x/image/draw"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ResizeImg(file multipart.File, width int, height int) ([]byte, error) {
|
|
||||||
// Read and decode image
|
|
||||||
img, _, err := image.Decode(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("decode error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new RGBA image
|
|
||||||
dst := image.NewRGBA(image.Rect(0, 0, width, height))
|
|
||||||
|
|
||||||
// Resize using high-quality interpolation
|
|
||||||
draw.CatmullRom.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil)
|
|
||||||
|
|
||||||
// Encode to PNG
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
if err := png.Encode(buf, dst); err != nil {
|
|
||||||
return nil, fmt.Errorf("encode error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
26
lib/links.go
26
lib/links.go
|
@ -1,26 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IconLink struct {
|
|
||||||
Name string
|
|
||||||
Href string
|
|
||||||
Icon template.HTML
|
|
||||||
}
|
|
||||||
|
|
||||||
type CardLink struct {
|
|
||||||
Name string
|
|
||||||
Href string
|
|
||||||
Description string
|
|
||||||
Date string
|
|
||||||
Tags []string
|
|
||||||
Internal bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type ButtonLink struct {
|
|
||||||
Name string
|
|
||||||
Href string
|
|
||||||
Internal bool
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gookit/color"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Error logging
|
|
||||||
var LogError = color.Style{
|
|
||||||
color.FgRed,
|
|
||||||
color.OpBold,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info logging
|
|
||||||
var LogInfo = color.Style{
|
|
||||||
color.FgCyan,
|
|
||||||
color.OpBold,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success logging
|
|
||||||
var LogSuccess = color.Style{
|
|
||||||
color.FgGreen,
|
|
||||||
color.OpBold,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning logging
|
|
||||||
var LogWarning = color.Style{
|
|
||||||
color.FgYellow,
|
|
||||||
color.OpBold,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug logging
|
|
||||||
var LogDebug = color.Style{
|
|
||||||
color.FgMagenta,
|
|
||||||
color.OpBold,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom logging
|
|
||||||
var LogCustom = color.Style{
|
|
||||||
color.FgWhite,
|
|
||||||
color.OpBold,
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io/fs"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FrontMatter struct {
|
|
||||||
Name string
|
|
||||||
Description string
|
|
||||||
Date string
|
|
||||||
Tags []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExtractFrontMatter(file fs.DirEntry, contentFS fs.FS) (CardLink, error) {
|
|
||||||
f, err := contentFS.Open(file.Name())
|
|
||||||
if err != nil {
|
|
||||||
return CardLink{}, fmt.Errorf("failed to open file: %w", err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
|
||||||
var lines []string
|
|
||||||
for scanner.Scan() {
|
|
||||||
lines = append(lines, scanner.Text())
|
|
||||||
}
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
return CardLink{}, fmt.Errorf("failed to read file: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
content := strings.Join(lines, "\n")
|
|
||||||
splitContent := strings.SplitN(content, "---", 3)
|
|
||||||
if len(splitContent) < 3 {
|
|
||||||
return CardLink{}, fmt.Errorf("invalid file format: %s", file.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
frontMatter := CardLink{}
|
|
||||||
if err := yaml.Unmarshal([]byte(splitContent[1]), &frontMatter); err != nil {
|
|
||||||
return CardLink{}, fmt.Errorf("failed to unmarshal frontmatter: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
md := goldmark.New(goldmark.WithExtensions())
|
|
||||||
var buf bytes.Buffer
|
|
||||||
if err := md.Convert([]byte(splitContent[2]), &buf); err != nil {
|
|
||||||
return CardLink{}, fmt.Errorf("failed to convert markdown: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return frontMatter, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func SplitFrontmatter(md []byte) (frontmatter []byte, content []byte, err error) {
|
|
||||||
parts := bytes.SplitN(md, []byte("---"), 3)
|
|
||||||
|
|
||||||
if len(parts) < 3 {
|
|
||||||
return nil, nil, errors.New("invalid or missing frontmatter")
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts[1], parts[2], nil
|
|
||||||
}
|
|
47
lib/posts.ts
Normal file
47
lib/posts.ts
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import { extractYaml } from "@std/front-matter";
|
||||||
|
import { join } from "@std/path";
|
||||||
|
|
||||||
|
const POSTS_DIR = "./posts";
|
||||||
|
|
||||||
|
// This is what gets parsed from the post front matter
|
||||||
|
interface FrontMatter {
|
||||||
|
title: string;
|
||||||
|
published_at: string;
|
||||||
|
blurb: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is what gets used for rendering
|
||||||
|
export interface Post {
|
||||||
|
slug: string;
|
||||||
|
title: string;
|
||||||
|
publishedAt: Date | null;
|
||||||
|
blurb: string;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPost(slug: string): Promise<Post> {
|
||||||
|
const text = await Deno.readTextFile(join(POSTS_DIR, `${slug}.md`));
|
||||||
|
const { attrs, body } = extractYaml<FrontMatter>(text);
|
||||||
|
const post = {
|
||||||
|
slug,
|
||||||
|
title: attrs.title,
|
||||||
|
publishedAt: attrs.published_at ? new Date(attrs.published_at) : null,
|
||||||
|
blurb: attrs.blurb,
|
||||||
|
content: body,
|
||||||
|
};
|
||||||
|
return post;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPosts(): Promise<Post[]> {
|
||||||
|
const files = Deno.readDir(POSTS_DIR);
|
||||||
|
const promises = [];
|
||||||
|
for await (const file of files) {
|
||||||
|
if (file.name.startsWith(".")) continue;
|
||||||
|
const slug = file.name.replace(".md", "");
|
||||||
|
promises.push(getPost(slug));
|
||||||
|
}
|
||||||
|
const posts = (await Promise.all(promises) as Post[])
|
||||||
|
.filter((post) => post.publishedAt instanceof Date);
|
||||||
|
posts.sort((a, b) => b.publishedAt!.getTime() - a.publishedAt!.getTime());
|
||||||
|
return posts;
|
||||||
|
}
|
66
lib/sse.go
66
lib/sse.go
|
@ -1,66 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import "sync"
|
|
||||||
|
|
||||||
type SSEServerType struct {
|
|
||||||
clients map[string]map[chan string]bool
|
|
||||||
mu sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
var SSEServer *SSEServerType
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
SSEServer = &SSEServerType{
|
|
||||||
clients: make(map[string]map[chan string]bool),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSSEServer() *SSEServerType {
|
|
||||||
return &SSEServerType{
|
|
||||||
clients: make(map[string]map[chan string]bool),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SSEServerType) AddClient(channel string, client chan string) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
if _, ok := s.clients[channel]; !ok {
|
|
||||||
s.clients[channel] = make(map[chan string]bool)
|
|
||||||
}
|
|
||||||
s.clients[channel][client] = true
|
|
||||||
|
|
||||||
LogInfo.Printf("\nClient connected to channel %s\n", channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SSEServerType) RemoveClient(channel string, client chan string) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
delete(s.clients[channel], client)
|
|
||||||
if len(s.clients[channel]) == 0 {
|
|
||||||
delete(s.clients, channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
LogInfo.Printf("\nClient disconnected from channel %s\n", channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SSEServerType) ClientCount(channel string) int {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
return len(s.clients[channel])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SSEServerType) SendSSE(channel string, message string) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for client := range s.clients[channel] {
|
|
||||||
client <- message
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
LogDebug.Printf("\nMessage broadcast on channel %s: %s\n", channel, message)
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
templatefs "atri.dad/pages/templates"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RenderTemplate(w http.ResponseWriter, layout string, partials []string, props interface{}) error {
|
|
||||||
// Get the name of the current file
|
|
||||||
_, filename, _, _ := runtime.Caller(1)
|
|
||||||
page := filepath.Base(filename)
|
|
||||||
page = page[:len(page)-len(filepath.Ext(page))] // remove the file extension
|
|
||||||
|
|
||||||
// Build the list of templates
|
|
||||||
templates := []string{
|
|
||||||
"layouts/" + layout + ".html",
|
|
||||||
page + ".html",
|
|
||||||
}
|
|
||||||
for _, partial := range partials {
|
|
||||||
templates = append(templates, "partials/"+partial+".html")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the templates
|
|
||||||
ts, err := template.ParseFS(templatefs.FS, templates...)
|
|
||||||
if err != nil {
|
|
||||||
LogError.Print(err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the layout template
|
|
||||||
err = ts.ExecuteTemplate(w, layout, props)
|
|
||||||
if err != nil {
|
|
||||||
LogError.Print(err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
102
main.go
102
main.go
|
@ -1,102 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"embed"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"atri.dad/api"
|
|
||||||
"atri.dad/lib"
|
|
||||||
"atri.dad/pages"
|
|
||||||
|
|
||||||
_ "atri.dad/docs"
|
|
||||||
"github.com/joho/godotenv"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/labstack/echo/v4/middleware"
|
|
||||||
echoSwagger "github.com/swaggo/echo-swagger"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed public/*
|
|
||||||
var PublicFS embed.FS
|
|
||||||
|
|
||||||
// @title Atri.dad API
|
|
||||||
// @version 1.0
|
|
||||||
// @description This is the API for atri.dad
|
|
||||||
// @host localhost:3000
|
|
||||||
// @BasePath /api
|
|
||||||
func main() {
|
|
||||||
// Load environment variables
|
|
||||||
godotenv.Load(".env")
|
|
||||||
|
|
||||||
// Initialize Echo router
|
|
||||||
e := echo.New()
|
|
||||||
|
|
||||||
// Middleware
|
|
||||||
e.Use(middleware.Logger())
|
|
||||||
e.Use(middleware.Recover())
|
|
||||||
e.Pre(middleware.RemoveTrailingSlash())
|
|
||||||
e.Use(middleware.RequestID())
|
|
||||||
e.Use(middleware.Secure())
|
|
||||||
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
|
||||||
Level: 5,
|
|
||||||
}))
|
|
||||||
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(50)))
|
|
||||||
|
|
||||||
// Add CORS middleware
|
|
||||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
|
||||||
AllowOrigins: []string{"https://atri.dad", "http://localhost:3000"},
|
|
||||||
AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete},
|
|
||||||
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
|
|
||||||
ExposeHeaders: []string{echo.HeaderContentType},
|
|
||||||
AllowCredentials: true,
|
|
||||||
MaxAge: 86400,
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Static server
|
|
||||||
fs := http.FS(PublicFS)
|
|
||||||
e.GET("/public/*", echo.WrapHandler(http.FileServer(fs)))
|
|
||||||
|
|
||||||
// Page routes
|
|
||||||
e.GET("/", pages.Home)
|
|
||||||
e.GET("/projects", pages.Projects)
|
|
||||||
e.GET("/talks", pages.Talks)
|
|
||||||
e.GET("/papers", pages.Papers)
|
|
||||||
e.GET("/posts", pages.Posts)
|
|
||||||
e.GET("/posts/:post", pages.Post)
|
|
||||||
e.GET("/tools", pages.Tools)
|
|
||||||
e.GET("/tools/resize", pages.Resize)
|
|
||||||
e.GET("/tools/ssedemo", pages.SSEDemo)
|
|
||||||
|
|
||||||
// API Routes:
|
|
||||||
apiGroup := e.Group("/api")
|
|
||||||
apiGroup.GET("/ping", api.Ping)
|
|
||||||
apiGroup.GET("/rss", api.RSSFeedHandler)
|
|
||||||
apiGroup.GET("/post/copy", api.PostCopy)
|
|
||||||
|
|
||||||
// Swagger endpoint
|
|
||||||
apiGroup.GET("/swagger/*", echoSwagger.WrapHandler)
|
|
||||||
|
|
||||||
apiGroup.GET("/sse", func(c echo.Context) error {
|
|
||||||
return api.SSE(c)
|
|
||||||
})
|
|
||||||
|
|
||||||
apiGroup.POST("/tools/sendsse", func(c echo.Context) error {
|
|
||||||
return api.SSEDemoSend(c)
|
|
||||||
})
|
|
||||||
|
|
||||||
apiGroup.POST("/tools/resize", api.ResizeHandler)
|
|
||||||
|
|
||||||
// Parse command-line arguments for IP and port
|
|
||||||
ip := flag.String("ip", "", "IP address to bind the server to")
|
|
||||||
port := flag.String("port", "3000", "Port to bind the server to")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
// Start server with HTTP/2 support
|
|
||||||
s := &http.Server{
|
|
||||||
Addr: fmt.Sprintf("%s:%s", *ip, *port),
|
|
||||||
Handler: e,
|
|
||||||
}
|
|
||||||
e.Logger.Fatal(e.StartServer(s))
|
|
||||||
lib.LogSuccess.Println("Server started on port", *port)
|
|
||||||
}
|
|
13
main.ts
Normal file
13
main.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/// <reference no-default-lib="true" />
|
||||||
|
/// <reference lib="dom" />
|
||||||
|
/// <reference lib="dom.iterable" />
|
||||||
|
/// <reference lib="dom.asynciterable" />
|
||||||
|
/// <reference lib="deno.ns" />
|
||||||
|
|
||||||
|
import "$std/dotenv/load.ts";
|
||||||
|
|
||||||
|
import { start } from "$fresh/server.ts";
|
||||||
|
import manifest from "./fresh.gen.ts";
|
||||||
|
import config from "./fresh.config.ts";
|
||||||
|
|
||||||
|
await start(manifest, config);
|
|
@ -1,22 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ExampleProps struct {
|
|
||||||
ExamplePropText string
|
|
||||||
}
|
|
||||||
|
|
||||||
func Example(c echo.Context) error {
|
|
||||||
props := ExampleProps{
|
|
||||||
ExamplePropText: "EXAMPLE TEXT HERE",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
106
pages/home.go
106
pages/home.go
File diff suppressed because one or more lines are too long
|
@ -1,32 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PapersProps struct {
|
|
||||||
Papers []lib.CardLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func Papers(c echo.Context) error {
|
|
||||||
papers := []lib.CardLink{
|
|
||||||
{
|
|
||||||
Name: "Bridging the Gap Between Social Networks and Healthcare",
|
|
||||||
Description: "An Assessment of the Need for Improved Patient-Patient, Patient-Provider, and Provider-Provider Sharing",
|
|
||||||
Href: "/public/files/bridging_the_gap_between_social_networks_and_healthcare.pdf",
|
|
||||||
Tags: []string{"masters", "coursework", "sna"},
|
|
||||||
Date: "January 03, 2025",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
props := PapersProps{
|
|
||||||
Papers: papers,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems", "cardlinks"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"html/template"
|
|
||||||
"io/fs"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
contentfs "atri.dad/content"
|
|
||||||
"atri.dad/lib"
|
|
||||||
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/yuin/goldmark"
|
|
||||||
highlighting "github.com/yuin/goldmark-highlighting/v2"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PostProps struct {
|
|
||||||
Content template.HTML
|
|
||||||
Name string
|
|
||||||
Description string
|
|
||||||
Date string
|
|
||||||
Tags []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func Post(c echo.Context) error {
|
|
||||||
postName := c.Param("post")
|
|
||||||
|
|
||||||
filePath := postName + ".md"
|
|
||||||
|
|
||||||
md, err := fs.ReadFile(contentfs.FS, filePath)
|
|
||||||
if err != nil {
|
|
||||||
println(err.Error())
|
|
||||||
http.Error(c.Response().Writer, "This post does not exist!", http.StatusNotFound)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
frontmatterBytes, content, err := lib.SplitFrontmatter(md)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var frontmatter lib.FrontMatter
|
|
||||||
if err := yaml.Unmarshal(frontmatterBytes, &frontmatter); err != nil {
|
|
||||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
markdown := goldmark.New(
|
|
||||||
goldmark.WithExtensions(
|
|
||||||
highlighting.NewHighlighting(
|
|
||||||
highlighting.WithStyle("fruity"),
|
|
||||||
highlighting.WithFormatOptions(
|
|
||||||
chromahtml.WithLineNumbers(true),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := markdown.Convert(content, &buf); err != nil {
|
|
||||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
props := PostProps{
|
|
||||||
Content: template.HTML(buf.String()),
|
|
||||||
Name: frontmatter.Name,
|
|
||||||
Description: frontmatter.Description,
|
|
||||||
Date: frontmatter.Date,
|
|
||||||
Tags: frontmatter.Tags,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "post", partials, props)
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
contentfs "atri.dad/content"
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PostsProps struct {
|
|
||||||
Posts []lib.CardLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func Posts(c echo.Context) error {
|
|
||||||
var posts []lib.CardLink
|
|
||||||
|
|
||||||
files, err := fs.ReadDir(contentfs.FS, ".")
|
|
||||||
if err != nil {
|
|
||||||
lib.LogError.Println(err)
|
|
||||||
http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if !file.IsDir() && strings.HasSuffix(file.Name(), ".md") {
|
|
||||||
frontMatter, err := lib.ExtractFrontMatter(file, contentfs.FS)
|
|
||||||
if err != nil {
|
|
||||||
lib.LogError.Println(err)
|
|
||||||
http.Error(c.Response().Writer, "There was an issue rendering the posts!", http.StatusInternalServerError)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
frontMatter.Href = "posts/" + strings.TrimSuffix(file.Name(), ".md")
|
|
||||||
frontMatter.Internal = true
|
|
||||||
|
|
||||||
posts = append(posts, frontMatter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const layout = "January 2 2006"
|
|
||||||
|
|
||||||
sort.Slice(posts, func(i, j int) bool {
|
|
||||||
iDate, err := time.Parse(layout, posts[i].Date)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
jDate, err := time.Parse(layout, posts[j].Date)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return iDate.Before(jDate)
|
|
||||||
})
|
|
||||||
|
|
||||||
props := PostsProps{
|
|
||||||
Posts: posts,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems", "cardlinks"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProjectProps struct {
|
|
||||||
Projects []lib.CardLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func Projects(c echo.Context) error {
|
|
||||||
projects := []lib.CardLink{
|
|
||||||
{
|
|
||||||
Name: "BlueSky PDS Manager",
|
|
||||||
Description: "A web-based BlueSky PDS Manager. Manage your invite codes and users with a simple web UI.",
|
|
||||||
Tags: []string{"astro", "atproto"},
|
|
||||||
Href: "https://pdsman.atri.dad",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Pollo",
|
|
||||||
Description: "A dead-simple real-time voting tool.",
|
|
||||||
Tags: []string{"golang", "htmx", "product"},
|
|
||||||
Href: "https://git.atri.dad/atridad/pollo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "GOTH Stack",
|
|
||||||
Description: "🚀 A Web Application Template Powered by HTMX + Go + Tailwind 🚀",
|
|
||||||
Tags: []string{"golang", "htmx", "template"},
|
|
||||||
Href: "https://git.atri.dad/atridad/goth.stack",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Himbot",
|
|
||||||
Description: "A discord bot written in Go. Loosly named after my username online (HimbothySwaggins).",
|
|
||||||
Tags: []string{"golang", "bot"},
|
|
||||||
Href: "https://git.atri.dad/atridad/himbot",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "loadr",
|
|
||||||
Description: "A lightweight REST load testing tool with robust support for different verbs, token auth, and performance reports.",
|
|
||||||
Tags: []string{"golang", "cli"},
|
|
||||||
Href: "https://git.atri.dad/atridad/loadr",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
props := ProjectProps{
|
|
||||||
Projects: projects,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems", "cardlinks"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TalkProps struct {
|
|
||||||
Talks []lib.CardLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func Talks(c echo.Context) error {
|
|
||||||
talks := []lib.CardLink{
|
|
||||||
{
|
|
||||||
Name: "Hypermedia as the engine of application state - an Introduction",
|
|
||||||
Description: "A talk on building reactive websites using tools like HTMX instead of JSON + JS. Will be presented at the Dev Edmonton Fabruary 2024 JS/Ruby/Python Meetup",
|
|
||||||
Href: "/public/files/hypermedia_talk_atridad.pdf",
|
|
||||||
Tags: []string{"golang", "htmx", "ssr"},
|
|
||||||
Date: "February 01, 2024",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Introduction to Social Network Analysis (SNA)",
|
|
||||||
Description: "Understanding Relationships in Social Structures",
|
|
||||||
Href: "/public/files/Understanding_Relationships_in_Social_Structures.pdf",
|
|
||||||
Tags: []string{"graphs", "social", "lecture"},
|
|
||||||
Date: "October 08, 2024",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
props := TalkProps{
|
|
||||||
Talks: talks,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems", "cardlinks"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Root
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
Researcher, Full-Stack Developer, and IT Professional.
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Root
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
<div class="home-page text-center">
|
|
||||||
<h1 class="text-4xl font-extrabold sm:text-8xl">
|
|
||||||
<span class="gradient-text">{{.Title}}</span>
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight sm:text-[2rem]">
|
|
||||||
{{.Subtitle}}
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<h2 class="mb-2 text-xl sm:text-[1.5rem]">Places I exist:</h2>
|
|
||||||
<div class="flex flex-row flex-wrap items-center justify-center gap-4">
|
|
||||||
{{range .Socials}}
|
|
||||||
{{template "iconlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<h2 class="mb-2 text-xl sm:text-[1.5rem]">Stuff I Use:</h2>
|
|
||||||
|
|
||||||
<div class="flex flex-row flex-wrap items-center justify-center gap-4">
|
|
||||||
{{range .Tech}}
|
|
||||||
{{template "iconlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div class="home-buttons-container">
|
|
||||||
{{range .ButtonsLinks}}
|
|
||||||
{{template "buttonlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,26 +0,0 @@
|
||||||
{{define "base"}}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en" data-theme="night">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<link rel="icon" href="/public/favicon.ico" />
|
|
||||||
<title>{{template "title" .}}</title>
|
|
||||||
<meta name="description" content="{{template "description" .}}">
|
|
||||||
<script defer src="https://analytics.atri.dad/script.js" data-website-id="0206740c-245f-402a-b433-125d6d48945a"></script>
|
|
||||||
<link href="/public/css/styles.css" rel="stylesheet" type="text/css" />
|
|
||||||
{{template "head" .}}
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
{{template "header" .}}
|
|
||||||
|
|
||||||
<main class="container flex flex-col items-center justify-center gap-3 sm:gap-6 p-4 text-center">
|
|
||||||
{{template "main" .}}
|
|
||||||
</main>
|
|
||||||
<script src="/public/js/htmx.base.js"></script>
|
|
||||||
<script src="/public/js/htmx.preload.js"></script>
|
|
||||||
{{template "foot" .}}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
{{end}}
|
|
|
@ -1,90 +0,0 @@
|
||||||
{{define "post"}}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en" data-theme="night">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<link rel="icon" href="/public/favicon.ico" />
|
|
||||||
<title>{{template "title" .}}</title>
|
|
||||||
<meta name="description" content="{{template "description" .}}">
|
|
||||||
<script defer src="https://analytics.atri.dad/script.js" data-website-id="0206740c-245f-402a-b433-125d6d48945a"></script>
|
|
||||||
<link href="/public/css/styles.css" rel="stylesheet" type="text/css" />
|
|
||||||
{{template "head" .}}
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
{{template "header" .}}
|
|
||||||
|
|
||||||
<main class="container mx-auto pt-6 pb-12 px-4 max-w-2xl">
|
|
||||||
<article>
|
|
||||||
<h1 class="text-3xl font-bold tracking-tight text-center mb-4">{{.Name}}</h1>
|
|
||||||
|
|
||||||
<div class="flex flex-row justify-center items-center gap-2">
|
|
||||||
{{if .Date}}
|
|
||||||
<div class="flex flex-row items-center gap-1 text-sm">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
|
||||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
||||||
class="lucide lucide-clock-4">
|
|
||||||
<circle cx="12" cy="12" r="10" />
|
|
||||||
<polyline points="12 6 12 12 16 14" />
|
|
||||||
</svg>
|
|
||||||
{{.Date}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if .Tags}}
|
|
||||||
<div class="flex flex-row items-center gap-1">
|
|
||||||
{{range .Tags}}
|
|
||||||
<span class="project-tag">#{{.}}</span>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
<div id="svgContainer" style="display: none;">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
|
|
||||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
||||||
class="lucide lucide-check-circle">
|
|
||||||
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
|
|
||||||
<path d="m9 11 3 3L22 4" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<button id="copyButton" aria-label="Copy Link to Post" hx-get="/api/post/copy" hx-swap="innerHTML"
|
|
||||||
class="post-icon-button"
|
|
||||||
hx-trigger="click delay:3s"
|
|
||||||
_='on click put #svgContainer.innerHTML into me.innerHTML then call navigator.clipboard.writeText(window.location.href)'>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
|
|
||||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
||||||
class="lucide lucide-copy">
|
|
||||||
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
|
|
||||||
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<a href="/posts" class="post-back-button" preload="mouseover">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
|
||||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
||||||
class="lucide lucide-undo-2">
|
|
||||||
<path d="M9 14 4 9l5-5" />
|
|
||||||
<path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5v0a5.5 5.5 0 0 1-5.5 5.5H11" />
|
|
||||||
</svg>
|
|
||||||
Back
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr class="mb-6 mt-2 border-t border-white opacity-20 w-full mx-auto" />
|
|
||||||
<div class="markdown text-left mx-auto">
|
|
||||||
{{template "main" .}}
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
<script src="/public/js/htmx.base.js"></script>
|
|
||||||
<script src="/public/js/htmx.preload.js"></script>
|
|
||||||
{{template "foot" .}}
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
{{end}}
|
|
|
@ -1,41 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Papers
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
Papers I've Written
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Papers
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
|
|
||||||
{{if .Papers}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
{{range .Papers}}
|
|
||||||
{{template "cardlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if not .Papers}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
|
||||||
Nothing to see here (yet)!
|
|
||||||
</h2>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,15 +0,0 @@
|
||||||
{{define "buttonlinks"}}
|
|
||||||
{{if eq true .Internal}}
|
|
||||||
|
|
||||||
<a class="btn btn-primary btn-outline btn-md lg:btn-lg" href={{.Href}} preload="mouseover">
|
|
||||||
{{.Name}}
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{{else}}
|
|
||||||
|
|
||||||
<a class="btn btn-primary btn-outline btn-md lg:btn-lg" href={{.Href}} target="_blank" rel="noreferrer">
|
|
||||||
{{.Name}}
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
|
@ -1,55 +0,0 @@
|
||||||
{{define "cardlinks"}}
|
|
||||||
<div class="project-card">
|
|
||||||
<div class="project-card-content">
|
|
||||||
<h2 class="project-card-title">{{.Name}}</h2>
|
|
||||||
|
|
||||||
{{if .Description}}
|
|
||||||
<p class="project-card-description">{{.Description}}</p>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if .Date}}
|
|
||||||
<p class="project-card-date">
|
|
||||||
<div class="flex flex-row flex-wrap items-center gap-1 text-md">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-clock-4"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
|
||||||
{{.Date}}
|
|
||||||
</div>
|
|
||||||
</p>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if .Tags}}
|
|
||||||
<div class="project-card-tags">
|
|
||||||
{{range .Tags}}
|
|
||||||
<span class="project-tag">#{{.}}</span>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if .Href}}
|
|
||||||
<div class="project-card-link">
|
|
||||||
{{if eq true .Internal}}
|
|
||||||
<a
|
|
||||||
role="button"
|
|
||||||
href={{.Href}}
|
|
||||||
aria-label={{.Name}}
|
|
||||||
class="project-link-button"
|
|
||||||
preload="mouseover"
|
|
||||||
>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-right"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>
|
|
||||||
</a>
|
|
||||||
{{else}}
|
|
||||||
<a
|
|
||||||
role="button"
|
|
||||||
href={{.Href}}
|
|
||||||
aria-label={{.Name}}
|
|
||||||
class="project-link-button"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
|
||||||
</a>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
{{define "header"}}
|
|
||||||
<div class="fill-green-500 tooltip tooltip-top badge badge-success"></div>
|
|
||||||
{{end}}
|
|
|
@ -1,49 +0,0 @@
|
||||||
{{define "header"}}
|
|
||||||
<header class="navbar">
|
|
||||||
<div class="navbar-start">
|
|
||||||
<a class="btn btn-ghost normal-case text-xl" href="/">{{template "navcontent".}}</a>
|
|
||||||
</div>
|
|
||||||
<div class="navbar-end">
|
|
||||||
<div class="dropdown dropdown-end">
|
|
||||||
<label tabindex="0" class="btn btn-ghost" id="navbar-toggle">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="menu-icon"><line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="18" y2="18"/></svg>
|
|
||||||
</label>
|
|
||||||
<ul
|
|
||||||
tabindex="0"
|
|
||||||
class="menu dropdown-content mt-3 shadow-md rounded-box z-50 nav-menu"
|
|
||||||
id="nav-menu"
|
|
||||||
>
|
|
||||||
{{template "navitems" .}}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
const navbarToggle = document.getElementById('navbar-toggle');
|
|
||||||
const navMenu = document.getElementById('nav-menu');
|
|
||||||
|
|
||||||
// Toggle menu on hamburger click
|
|
||||||
navbarToggle.addEventListener('click', function(e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
navMenu.classList.toggle('show');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Close menu when clicking outside
|
|
||||||
document.addEventListener('click', function(e) {
|
|
||||||
if (!navMenu.contains(e.target) && !navbarToggle.contains(e.target)) {
|
|
||||||
navMenu.classList.remove('show');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Close menu when clicking on a menu item
|
|
||||||
const menuItems = navMenu.querySelectorAll('a');
|
|
||||||
menuItems.forEach(item => {
|
|
||||||
item.addEventListener('click', function() {
|
|
||||||
navMenu.classList.remove('show');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
|
@ -1,5 +0,0 @@
|
||||||
{{define "iconlinks"}}
|
|
||||||
<a class="icon-link" href={{.Href}} target="_blank" rel="me" aria-label={{.Name}}>
|
|
||||||
{{.Icon}}
|
|
||||||
</a>
|
|
||||||
{{end}}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{{define "navitems"}}
|
|
||||||
<li><a href="/">Home</a></li>
|
|
||||||
<li><a href="/projects">Projects</a></li>
|
|
||||||
<li><a href="/papers">Papers</a></li>
|
|
||||||
<li><a href="/talks">Talks</a></li>
|
|
||||||
<li><a href="/posts">Posts</a></li>
|
|
||||||
<li><a href="/tools">Tools</a></li>
|
|
||||||
{{end}}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Post // {{.Name}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
{{.Description}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Post // {{.Name}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
{{.Content}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
<script src="/public/js/hyperscript.js"></script>
|
|
||||||
{{end}}
|
|
|
@ -1,41 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Posts
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
Posts I've Written
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Posts
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
|
|
||||||
{{if .Posts}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
{{range .Posts}}
|
|
||||||
{{template "cardlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if not .Posts}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
|
||||||
Nothing to see here (yet)!
|
|
||||||
</h2>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,41 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Projects
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
Projects I've Done
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Projects
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
|
|
||||||
{{if .Projects}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
{{range .Projects}}
|
|
||||||
{{template "cardlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if not .Projects}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
|
||||||
Nothing to see here (yet)!
|
|
||||||
</h2>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,41 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Talks
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
Talks I've Given
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Talks
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
|
|
||||||
{{if .Talks}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
{{range .Talks}}
|
|
||||||
{{template "cardlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if not .Talks}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
|
||||||
Nothing to see here (yet)!
|
|
||||||
</h2>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package templatefs
|
|
||||||
|
|
||||||
import "embed"
|
|
||||||
|
|
||||||
//go:embed *
|
|
||||||
var FS embed.FS
|
|
|
@ -1,43 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Tools
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
Tools I've Built
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Tools
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
|
|
||||||
<div class="tools-page">
|
|
||||||
{{if .Tools}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
{{range .Tools}}
|
|
||||||
{{template "cardlinks" .}}
|
|
||||||
{{end}}
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if not .Tools}}
|
|
||||||
<div class="card-grid-container">
|
|
||||||
<section class="card-grid">
|
|
||||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
|
||||||
Nothing to see here (yet)!
|
|
||||||
</h2>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,44 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Tools // Resizer
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
A tool to re-size images.
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Tools // Resizer
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
<div class="tool-page">
|
|
||||||
<h1>Image Resizer</h1>
|
|
||||||
|
|
||||||
<p>Upload and resize your images quickly and easily. Select an image file, specify dimensions, and get a resized version instantly.</p>
|
|
||||||
|
|
||||||
<form action="/api/tools/resize" method="post" enctype="multipart/form-data" class="form-group">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="image">Select image to resize:</label>
|
|
||||||
<input type="file" id="image" name="image" accept=".png,.jpg,.jpeg" required />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="newWidth">New width (px):</label>
|
|
||||||
<input type="number" id="newWidth" name="width" min="1" required />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="newHeight">New height (px):</label>
|
|
||||||
<input type="number" id="newHeight" name="height" min="1" required />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="tool-button">Resize Image</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
{{end}}
|
|
|
@ -1,41 +0,0 @@
|
||||||
{{define "title"}}
|
|
||||||
Atridad Lahiji // Tools // SSE Demo
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "navcontent"}}
|
|
||||||
Atridad Lahiji // Tools // SSE Demo
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "description"}}
|
|
||||||
A demo of my SSE implementation.
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "head"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
<div class="tool-page">
|
|
||||||
<h1>Server Sent Events Demo</h1>
|
|
||||||
|
|
||||||
<p>This page demonstrates the use of the <a href="https://htmx.org/extensions/sse/" class="tool-link">HTMX SSE
|
|
||||||
Extension</a> to receive Server Sent Events on the "default" channel.</p>
|
|
||||||
<p>Any events received on the "default" channel will appear below:</p>
|
|
||||||
<div hx-ext="sse" sse-connect="/api/sse" sse-swap="message" class="sse-message-container">
|
|
||||||
Waiting for SSE Message...
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>Here you can send messages on the default channel:</p>
|
|
||||||
<form hx-post="/api/tools/sendsse" hx-trigger="submit" hx-swap="none" class="form-group">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="message">Message</label>
|
|
||||||
<input type="text" id="message" name="message" value="Hello world!" placeholder="Enter your message here" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="tool-button">Send Event</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "foot"}}
|
|
||||||
<script src="/public/js/htmx.sse.js"></script>
|
|
||||||
{{end}}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ToolsProps struct {
|
|
||||||
Tools []lib.CardLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func Tools(c echo.Context) error {
|
|
||||||
tools := []lib.CardLink{
|
|
||||||
{
|
|
||||||
Name: "Server Sent Events Demo",
|
|
||||||
Description: "Server Sent Events Demo",
|
|
||||||
Href: "/tools/ssedemo",
|
|
||||||
Internal: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Image Resizer",
|
|
||||||
Description: "Image Resizer Tool",
|
|
||||||
Href: "/tools/resize",
|
|
||||||
Internal: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
props := ToolsProps{
|
|
||||||
Tools: tools,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems", "cardlinks"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ResizeProps struct {
|
|
||||||
Talks []lib.CardLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func Resize(c echo.Context) error {
|
|
||||||
talks := []lib.CardLink{
|
|
||||||
{
|
|
||||||
Name: "How to ship less JavaScript",
|
|
||||||
Description: "A talk on building websites while being mindful of the JavaScript we ship. Presented at the Dev Edmonton July 2023 JS/Ruby/Python Meetup",
|
|
||||||
Href: "https://github.com/atridadl/devedmonton-july-2023",
|
|
||||||
Tags: []string{"astro", "ssr"},
|
|
||||||
Date: "July 06, 2023",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Hypermedia as the engine of application state - an Introduction",
|
|
||||||
Description: "A talk on building reactive websites using tools like HTMX instead of JSON + JS. Will be presented at the Dev Edmonton Fabruary 2024 JS/Ruby/Python Meetup",
|
|
||||||
// Href: lib.GeneratePublicURL("hypermedia_talk_atridad.pdf"),
|
|
||||||
Tags: []string{"golang", "htmx", "ssr"},
|
|
||||||
Date: "February 01, 2024",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
props := TalkProps{
|
|
||||||
Talks: talks,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems", "cardlinks"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SSEDemo(c echo.Context) error {
|
|
||||||
// Specify the partials used by this page
|
|
||||||
partials := []string{"header", "navitems"}
|
|
||||||
|
|
||||||
// Render the template
|
|
||||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, nil)
|
|
||||||
}
|
|
27
posts/favourite_tools_list.md
Normal file
27
posts/favourite_tools_list.md
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
---
|
||||||
|
title: Current List of Favourite Tools
|
||||||
|
published_at: 2025-01-28T15:00:00.000Z
|
||||||
|
---
|
||||||
|
|
||||||
|
I change what I use _constantly_ in order to find something that feels just
|
||||||
|
right. I wanted to share them here and update them here so when someone asks, I
|
||||||
|
can just point them to this article.
|
||||||
|
|
||||||
|
1. Sublime Text - Currently my favourite text editor. Fast, simple, and
|
||||||
|
extensible. Just a joy to use!
|
||||||
|
2. Sublime Merge - Honestly one of the fastest and best looking git GUIs around!
|
||||||
|
Awesome for visualizing changes when you have larger code changes.
|
||||||
|
3. Ghostty - A Zig based terminal emulator by one of the founders of Hashicorp.
|
||||||
|
Runs great on MacOS and Linux. No windows for those who are into that.
|
||||||
|
4. OrbStack - A faster alternative to Docker Desktop that also runs VMs!
|
||||||
|
5. Bitwarden - An open-source password manager. Easy to self host with
|
||||||
|
Vaultwarden and with the recent updates, it has SSH Agent support!
|
||||||
|
6. iA Writer - A minimalist Markdown editor. For MacOS and Windows only, but
|
||||||
|
really the MacOS version is the most mature. Awesome for focus.
|
||||||
|
7. Dataflare - A simple but powerful cross-platform database client. Supports
|
||||||
|
most common databases, including LibSQL which is rare!
|
||||||
|
8. Bruno - A simple and powerful API client, similar to Postman. An critical
|
||||||
|
tool to debug API endpoints.
|
||||||
|
|
||||||
|
I hope you found this helpful! This will be periodically updated to avoid
|
||||||
|
outdated recommendations.
|
10
posts/welcome.md
Normal file
10
posts/welcome.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
title: Welcome!
|
||||||
|
published_at: 2024-10-20T15:00:00.000Z
|
||||||
|
---
|
||||||
|
|
||||||
|
Welcome to my site! This is a place for me to share my thoughts and updates on
|
||||||
|
my projects. I hope you find something interesting here.
|
||||||
|
|
||||||
|
Feel free to reach out if you have any questions or comments. I'd love to hear
|
||||||
|
from you! I can be reached by email at [me@atri.dad](mailto:me@atri.dad).
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 145 KiB |
File diff suppressed because one or more lines are too long
|
@ -1,418 +0,0 @@
|
||||||
(function () {
|
|
||||||
/**
|
|
||||||
* This adds the "preload" extension to htmx. The extension will
|
|
||||||
* preload the targets of elements with "preload" attribute if:
|
|
||||||
* - they also have `href`, `hx-get` or `data-hx-get` attributes
|
|
||||||
* - they are radio buttons, checkboxes, select elements and submit
|
|
||||||
* buttons of forms with `method="get"` or `hx-get` attributes
|
|
||||||
* The extension relies on browser cache and for it to work
|
|
||||||
* server response must include `Cache-Control` header
|
|
||||||
* e.g. `Cache-Control: private, max-age=60`.
|
|
||||||
* For more details @see https://htmx.org/extensions/preload/
|
|
||||||
*/
|
|
||||||
|
|
||||||
htmx.defineExtension("preload", {
|
|
||||||
onEvent: function (name, event) {
|
|
||||||
// Process preload attributes on `htmx:afterProcessNode`
|
|
||||||
if (name === "htmx:afterProcessNode") {
|
|
||||||
// Initialize all nodes with `preload` attribute
|
|
||||||
const parent = event.target || event.detail.elt;
|
|
||||||
const preloadNodes = [
|
|
||||||
...(parent.hasAttribute("preload") ? [parent] : []),
|
|
||||||
...parent.querySelectorAll("[preload]"),
|
|
||||||
];
|
|
||||||
preloadNodes.forEach(function (node) {
|
|
||||||
// Initialize the node with the `preload` attribute
|
|
||||||
init(node);
|
|
||||||
|
|
||||||
// Initialize all child elements which has
|
|
||||||
// `href`, `hx-get` or `data-hx-get` attributes
|
|
||||||
node.querySelectorAll("[href],[hx-get],[data-hx-get]").forEach(init);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intercept HTMX preload requests on `htmx:beforeRequest` and
|
|
||||||
// send them as XHR requests instead to avoid side-effects,
|
|
||||||
// such as showing loading indicators while preloading data.
|
|
||||||
if (name === "htmx:beforeRequest") {
|
|
||||||
const requestHeaders = event.detail.requestConfig.headers;
|
|
||||||
if (
|
|
||||||
!(
|
|
||||||
"HX-Preloaded" in requestHeaders &&
|
|
||||||
requestHeaders["HX-Preloaded"] === "true"
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
// Reuse XHR created by HTMX with replaced callbacks
|
|
||||||
const xhr = event.detail.xhr;
|
|
||||||
xhr.onload = function () {
|
|
||||||
processResponse(event.detail.elt, xhr.responseText);
|
|
||||||
};
|
|
||||||
xhr.onerror = null;
|
|
||||||
xhr.onabort = null;
|
|
||||||
xhr.ontimeout = null;
|
|
||||||
xhr.send();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize `node`, set up event handlers based on own or inherited
|
|
||||||
* `preload` attributes and set `node.preloadState` to `READY`.
|
|
||||||
*
|
|
||||||
* `node.preloadState` can have these values:
|
|
||||||
* - `READY` - event handlers have been set up and node is ready to preload
|
|
||||||
* - `TIMEOUT` - a triggering event has been fired, but `node` is not
|
|
||||||
* yet being loaded because some time need to pass first e.g. user
|
|
||||||
* has to keep hovering over an element for 100ms for preload to start
|
|
||||||
* - `LOADING` means that `node` is in the process of being preloaded
|
|
||||||
* - `DONE` means that the preloading process is complete and `node`
|
|
||||||
* doesn't need a repeated preload (indicated by preload="always")
|
|
||||||
* @param {Node} node
|
|
||||||
*/
|
|
||||||
function init(node) {
|
|
||||||
// Guarantee that each node is initialized only once
|
|
||||||
if (node.preloadState !== undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isValidNodeForPreloading(node)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize form element preloading
|
|
||||||
if (node instanceof HTMLFormElement) {
|
|
||||||
const form = node;
|
|
||||||
// Only initialize forms with `method="get"` or `hx-get` attributes
|
|
||||||
if (
|
|
||||||
!(
|
|
||||||
(form.hasAttribute("method") && form.method === "get") ||
|
|
||||||
form.hasAttribute("hx-get") ||
|
|
||||||
form.hasAttribute("hx-data-get")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < form.elements.length; i++) {
|
|
||||||
const element = form.elements.item(i);
|
|
||||||
init(element);
|
|
||||||
element.labels.forEach(init);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process node configuration from preload attribute
|
|
||||||
let preloadAttr = getClosestAttribute(node, "preload");
|
|
||||||
node.preloadAlways = preloadAttr && preloadAttr.includes("always");
|
|
||||||
if (node.preloadAlways) {
|
|
||||||
preloadAttr = preloadAttr.replace("always", "").trim();
|
|
||||||
}
|
|
||||||
let triggerEventName = preloadAttr || "mousedown";
|
|
||||||
|
|
||||||
// Set up event handlers listening for triggering events
|
|
||||||
const needsTimeout = triggerEventName === "mouseover";
|
|
||||||
node.addEventListener(
|
|
||||||
triggerEventName,
|
|
||||||
getEventHandler(node, needsTimeout),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add `touchstart` listener for touchscreen support
|
|
||||||
// if `mousedown` or `mouseover` is used
|
|
||||||
if (triggerEventName === "mousedown" || triggerEventName === "mouseover") {
|
|
||||||
node.addEventListener("touchstart", getEventHandler(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If `mouseover` is used, set up `mouseout` listener,
|
|
||||||
// which will abort preloading if user moves mouse outside
|
|
||||||
// the element in less than 100ms after hovering over it
|
|
||||||
if (triggerEventName === "mouseover") {
|
|
||||||
node.addEventListener("mouseout", function (evt) {
|
|
||||||
if (evt.target === node && node.preloadState === "TIMEOUT") {
|
|
||||||
node.preloadState = "READY";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark the node as ready to be preloaded
|
|
||||||
node.preloadState = "READY";
|
|
||||||
|
|
||||||
// This event can be used to load content immediately
|
|
||||||
htmx.trigger(node, "preload:init");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return event handler which can be called by event listener to start
|
|
||||||
* the preloading process of `node` with or without a timeout
|
|
||||||
* @param {Node} node
|
|
||||||
* @param {boolean=} needsTimeout
|
|
||||||
* @returns {function(): void}
|
|
||||||
*/
|
|
||||||
function getEventHandler(node, needsTimeout = false) {
|
|
||||||
return function () {
|
|
||||||
// Do not preload uninitialized nodes, nodes which are in process
|
|
||||||
// of being preloaded or have been preloaded and don't need repeat
|
|
||||||
if (node.preloadState !== "READY") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needsTimeout) {
|
|
||||||
node.preloadState = "TIMEOUT";
|
|
||||||
const timeoutMs = 100;
|
|
||||||
window.setTimeout(function () {
|
|
||||||
if (node.preloadState === "TIMEOUT") {
|
|
||||||
node.preloadState = "READY";
|
|
||||||
load(node);
|
|
||||||
}
|
|
||||||
}, timeoutMs);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
load(node);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Preload the target of node, which can be:
|
|
||||||
* - hx-get or data-hx-get attribute
|
|
||||||
* - href or form action attribute
|
|
||||||
* @param {Node} node
|
|
||||||
*/
|
|
||||||
function load(node) {
|
|
||||||
// Do not preload uninitialized nodes, nodes which are in process
|
|
||||||
// of being preloaded or have been preloaded and don't need repeat
|
|
||||||
if (node.preloadState !== "READY") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
node.preloadState = "LOADING";
|
|
||||||
|
|
||||||
// Load nodes with `hx-get` or `data-hx-get` attribute
|
|
||||||
// Forms don't reach this because only their elements are initialized
|
|
||||||
const hxGet =
|
|
||||||
node.getAttribute("hx-get") || node.getAttribute("data-hx-get");
|
|
||||||
if (hxGet) {
|
|
||||||
sendHxGetRequest(hxGet, node);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load nodes with `href` attribute
|
|
||||||
const hxBoost = getClosestAttribute(node, "hx-boost") === "true";
|
|
||||||
if (node.hasAttribute("href")) {
|
|
||||||
const url = node.getAttribute("href");
|
|
||||||
if (hxBoost) {
|
|
||||||
sendHxGetRequest(url, node);
|
|
||||||
} else {
|
|
||||||
sendXmlGetRequest(url, node);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load form elements
|
|
||||||
if (isPreloadableFormElement(node)) {
|
|
||||||
const url =
|
|
||||||
node.form.getAttribute("action") ||
|
|
||||||
node.form.getAttribute("hx-get") ||
|
|
||||||
node.form.getAttribute("data-hx-get");
|
|
||||||
const formData = htmx.values(node.form);
|
|
||||||
const isStandardForm = !(
|
|
||||||
node.form.getAttribute("hx-get") ||
|
|
||||||
node.form.getAttribute("data-hx-get") ||
|
|
||||||
hxBoost
|
|
||||||
);
|
|
||||||
const sendGetRequest = isStandardForm
|
|
||||||
? sendXmlGetRequest
|
|
||||||
: sendHxGetRequest;
|
|
||||||
|
|
||||||
// submit button
|
|
||||||
if (node.type === "submit") {
|
|
||||||
sendGetRequest(url, node.form, formData);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// select
|
|
||||||
const inputName = node.name || node.control.name;
|
|
||||||
if (node.tagName === "SELECT") {
|
|
||||||
Array.from(node.options).forEach((option) => {
|
|
||||||
if (option.selected) return;
|
|
||||||
formData.set(inputName, option.value);
|
|
||||||
const formDataOrdered = forceFormDataInOrder(node.form, formData);
|
|
||||||
sendGetRequest(url, node.form, formDataOrdered);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// radio and checkbox
|
|
||||||
const inputType =
|
|
||||||
node.getAttribute("type") || node.control.getAttribute("type");
|
|
||||||
const nodeValue = node.value || node.control?.value;
|
|
||||||
if (inputType === "radio") {
|
|
||||||
formData.set(inputName, nodeValue);
|
|
||||||
} else if (inputType === "checkbox") {
|
|
||||||
const inputValues = formData.getAll(inputName);
|
|
||||||
if (inputValues.includes(nodeValue)) {
|
|
||||||
formData[inputName] = inputValues.filter(
|
|
||||||
(value) => value !== nodeValue,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
formData.append(inputName, nodeValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const formDataOrdered = forceFormDataInOrder(node.form, formData);
|
|
||||||
sendGetRequest(url, node.form, formDataOrdered);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Force formData values to be in the order of form elements.
|
|
||||||
* This is useful to apply after alternating formData values
|
|
||||||
* and before passing them to a HTTP request because cache is
|
|
||||||
* sensitive to GET parameter order e.g., cached `/link?a=1&b=2`
|
|
||||||
* will not be used for `/link?b=2&a=1`.
|
|
||||||
* @param {HTMLFormElement} form
|
|
||||||
* @param {FormData} formData
|
|
||||||
* @returns {FormData}
|
|
||||||
*/
|
|
||||||
function forceFormDataInOrder(form, formData) {
|
|
||||||
const formElements = form.elements;
|
|
||||||
const orderedFormData = new FormData();
|
|
||||||
for (let i = 0; i < formElements.length; i++) {
|
|
||||||
const element = formElements.item(i);
|
|
||||||
if (formData.has(element.name) && element.tagName === "SELECT") {
|
|
||||||
orderedFormData.append(element.name, formData.get(element.name));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
formData.has(element.name) &&
|
|
||||||
formData.getAll(element.name).includes(element.value)
|
|
||||||
) {
|
|
||||||
orderedFormData.append(element.name, element.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return orderedFormData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send GET request with `hx-request` headers as if `sourceNode`
|
|
||||||
* target was loaded. Send alternated values if `formData` is set.
|
|
||||||
*
|
|
||||||
* Note that this request is intercepted and sent as XMLHttpRequest.
|
|
||||||
* It is necessary to use `htmx.ajax` to acquire correct headers which
|
|
||||||
* HTMX and extensions add based on `sourceNode`. But it cannot be used
|
|
||||||
* to perform the request due to side-effects e.g. loading indicators.
|
|
||||||
* @param {string} url
|
|
||||||
* @param {Node} sourceNode
|
|
||||||
* @param {FormData=} formData
|
|
||||||
*/
|
|
||||||
function sendHxGetRequest(url, sourceNode, formData = undefined) {
|
|
||||||
htmx.ajax("GET", url, {
|
|
||||||
source: sourceNode,
|
|
||||||
values: formData,
|
|
||||||
headers: { "HX-Preloaded": "true" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send XML GET request to `url`. Send `formData` as URL params if set.
|
|
||||||
* @param {string} url
|
|
||||||
* @param {Node} sourceNode
|
|
||||||
* @param {FormData=} formData
|
|
||||||
*/
|
|
||||||
function sendXmlGetRequest(url, sourceNode, formData = undefined) {
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
if (formData) {
|
|
||||||
url += "?" + new URLSearchParams(formData.entries()).toString();
|
|
||||||
}
|
|
||||||
xhr.open("GET", url);
|
|
||||||
xhr.setRequestHeader("HX-Preloaded", "true");
|
|
||||||
xhr.onload = function () {
|
|
||||||
processResponse(sourceNode, xhr.responseText);
|
|
||||||
};
|
|
||||||
xhr.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process request response by marking node `DONE` to prevent repeated
|
|
||||||
* requests, except if preload attribute contains `always`,
|
|
||||||
* and load linked resources (e.g. images) returned in the response
|
|
||||||
* if `preload-images` attribute is `true`
|
|
||||||
* @param {Node} node
|
|
||||||
* @param {string} responseText
|
|
||||||
*/
|
|
||||||
function processResponse(node, responseText) {
|
|
||||||
node.preloadState = node.preloadAlways ? "READY" : "DONE";
|
|
||||||
|
|
||||||
if (getClosestAttribute(node, "preload-images") === "true") {
|
|
||||||
// Load linked resources
|
|
||||||
document.createElement("div").innerHTML = responseText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets attribute value from node or one of its parents
|
|
||||||
* @param {Node} node
|
|
||||||
* @param {string} attribute
|
|
||||||
* @returns { string | undefined }
|
|
||||||
*/
|
|
||||||
function getClosestAttribute(node, attribute) {
|
|
||||||
if (node == undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
node.getAttribute(attribute) ||
|
|
||||||
node.getAttribute("data-" + attribute) ||
|
|
||||||
getClosestAttribute(node.parentElement, attribute)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if node is valid for preloading and should be
|
|
||||||
* initialized by setting up event listeners and handlers
|
|
||||||
* @param {Node} node
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function isValidNodeForPreloading(node) {
|
|
||||||
// Add listeners only to nodes which include "GET" transactions
|
|
||||||
// or preloadable "GET" form elements
|
|
||||||
const getReqAttrs = ["href", "hx-get", "data-hx-get"];
|
|
||||||
const includesGetRequest = (node) =>
|
|
||||||
getReqAttrs.some((a) => node.hasAttribute(a)) || node.method === "get";
|
|
||||||
const isPreloadableGetFormElement =
|
|
||||||
node.form instanceof HTMLFormElement &&
|
|
||||||
includesGetRequest(node.form) &&
|
|
||||||
isPreloadableFormElement(node);
|
|
||||||
if (!includesGetRequest(node) && !isPreloadableGetFormElement) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't preload <input> elements contained in <label>
|
|
||||||
// to prevent sending two requests. Interaction on <input> in a
|
|
||||||
// <label><input></input></label> situation activates <label> too.
|
|
||||||
if (node instanceof HTMLInputElement && node.closest("label")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if node is a form element which can be preloaded,
|
|
||||||
* i.e., `radio`, `checkbox`, `select` or `submit` button
|
|
||||||
* or a `label` of a form element which can be preloaded.
|
|
||||||
* @param {Node} node
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function isPreloadableFormElement(node) {
|
|
||||||
if (node instanceof HTMLInputElement || node instanceof HTMLButtonElement) {
|
|
||||||
const type = node.getAttribute("type");
|
|
||||||
return ["checkbox", "radio", "submit"].includes(type);
|
|
||||||
}
|
|
||||||
if (node instanceof HTMLLabelElement) {
|
|
||||||
return node.control && isPreloadableFormElement(node.control);
|
|
||||||
}
|
|
||||||
return node instanceof HTMLSelectElement;
|
|
||||||
}
|
|
||||||
})();
|
|
|
@ -1,293 +0,0 @@
|
||||||
/*
|
|
||||||
Server Sent Events Extension
|
|
||||||
============================
|
|
||||||
This extension adds support for Server Sent Events to htmx. See /www/extensions/sse.md for usage instructions.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
/** @type {import("../htmx").HtmxInternalApi} */
|
|
||||||
var api;
|
|
||||||
|
|
||||||
htmx.defineExtension("sse", {
|
|
||||||
/**
|
|
||||||
* Init saves the provided reference to the internal HTMX API.
|
|
||||||
*
|
|
||||||
* @param {import("../htmx").HtmxInternalApi} api
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
init: function (apiRef) {
|
|
||||||
// store a reference to the internal API.
|
|
||||||
api = apiRef;
|
|
||||||
|
|
||||||
// set a function in the public API for creating new EventSource objects
|
|
||||||
if (htmx.createEventSource == undefined) {
|
|
||||||
htmx.createEventSource = createEventSource;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
getSelectors: function () {
|
|
||||||
return [
|
|
||||||
"[sse-connect]",
|
|
||||||
"[data-sse-connect]",
|
|
||||||
"[sse-swap]",
|
|
||||||
"[data-sse-swap]",
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* onEvent handles all events passed to this extension.
|
|
||||||
*
|
|
||||||
* @param {string} name
|
|
||||||
* @param {Event} evt
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
onEvent: function (name, evt) {
|
|
||||||
var parent = evt.target || evt.detail.elt;
|
|
||||||
switch (name) {
|
|
||||||
case "htmx:beforeCleanupElement":
|
|
||||||
var internalData = api.getInternalData(parent);
|
|
||||||
// Try to remove remove an EventSource when elements are removed
|
|
||||||
var source = internalData.sseEventSource;
|
|
||||||
if (source) {
|
|
||||||
api.triggerEvent(parent, "htmx:sseClose", {
|
|
||||||
source,
|
|
||||||
type: "nodeReplaced",
|
|
||||||
});
|
|
||||||
internalData.sseEventSource.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Try to create EventSources when elements are processed
|
|
||||||
case "htmx:afterProcessNode":
|
|
||||||
ensureEventSourceOnElement(parent);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/// ////////////////////////////////////////////
|
|
||||||
// HELPER FUNCTIONS
|
|
||||||
/// ////////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* createEventSource is the default method for creating new EventSource objects.
|
|
||||||
* it is hoisted into htmx.config.createEventSource to be overridden by the user, if needed.
|
|
||||||
*
|
|
||||||
* @param {string} url
|
|
||||||
* @returns EventSource
|
|
||||||
*/
|
|
||||||
function createEventSource(url) {
|
|
||||||
return new EventSource(url, { withCredentials: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* registerSSE looks for attributes that can contain sse events, right
|
|
||||||
* now hx-trigger and sse-swap and adds listeners based on these attributes too
|
|
||||||
* the closest event source
|
|
||||||
*
|
|
||||||
* @param {HTMLElement} elt
|
|
||||||
*/
|
|
||||||
function registerSSE(elt) {
|
|
||||||
// Add message handlers for every `sse-swap` attribute
|
|
||||||
if (api.getAttributeValue(elt, "sse-swap")) {
|
|
||||||
// Find closest existing event source
|
|
||||||
var sourceElement = api.getClosestMatch(elt, hasEventSource);
|
|
||||||
if (sourceElement == null) {
|
|
||||||
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
|
|
||||||
return null; // no eventsource in parentage, orphaned element
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set internalData and source
|
|
||||||
var internalData = api.getInternalData(sourceElement);
|
|
||||||
var source = internalData.sseEventSource;
|
|
||||||
|
|
||||||
var sseSwapAttr = api.getAttributeValue(elt, "sse-swap");
|
|
||||||
var sseEventNames = sseSwapAttr.split(",");
|
|
||||||
|
|
||||||
for (var i = 0; i < sseEventNames.length; i++) {
|
|
||||||
const sseEventName = sseEventNames[i].trim();
|
|
||||||
const listener = function (event) {
|
|
||||||
// If the source is missing then close SSE
|
|
||||||
if (maybeCloseSSESource(sourceElement)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the body no longer contains the element, remove the listener
|
|
||||||
if (!api.bodyContains(elt)) {
|
|
||||||
source.removeEventListener(sseEventName, listener);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// swap the response into the DOM and trigger a notification
|
|
||||||
if (!api.triggerEvent(elt, "htmx:sseBeforeMessage", event)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
swap(elt, event.data);
|
|
||||||
api.triggerEvent(elt, "htmx:sseMessage", event);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register the new listener
|
|
||||||
api.getInternalData(elt).sseEventListener = listener;
|
|
||||||
source.addEventListener(sseEventName, listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add message handlers for every `hx-trigger="sse:*"` attribute
|
|
||||||
if (api.getAttributeValue(elt, "hx-trigger")) {
|
|
||||||
// Find closest existing event source
|
|
||||||
var sourceElement = api.getClosestMatch(elt, hasEventSource);
|
|
||||||
if (sourceElement == null) {
|
|
||||||
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
|
|
||||||
return null; // no eventsource in parentage, orphaned element
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set internalData and source
|
|
||||||
var internalData = api.getInternalData(sourceElement);
|
|
||||||
var source = internalData.sseEventSource;
|
|
||||||
|
|
||||||
var triggerSpecs = api.getTriggerSpecs(elt);
|
|
||||||
triggerSpecs.forEach(function (ts) {
|
|
||||||
if (ts.trigger.slice(0, 4) !== "sse:") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var listener = function (event) {
|
|
||||||
if (maybeCloseSSESource(sourceElement)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!api.bodyContains(elt)) {
|
|
||||||
source.removeEventListener(ts.trigger.slice(4), listener);
|
|
||||||
}
|
|
||||||
// Trigger events to be handled by the rest of htmx
|
|
||||||
htmx.trigger(elt, ts.trigger, event);
|
|
||||||
htmx.trigger(elt, "htmx:sseMessage", event);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register the new listener
|
|
||||||
api.getInternalData(elt).sseEventListener = listener;
|
|
||||||
source.addEventListener(ts.trigger.slice(4), listener);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ensureEventSourceOnElement creates a new EventSource connection on the provided element.
|
|
||||||
* If a usable EventSource already exists, then it is returned. If not, then a new EventSource
|
|
||||||
* is created and stored in the element's internalData.
|
|
||||||
* @param {HTMLElement} elt
|
|
||||||
* @param {number} retryCount
|
|
||||||
* @returns {EventSource | null}
|
|
||||||
*/
|
|
||||||
function ensureEventSourceOnElement(elt, retryCount) {
|
|
||||||
if (elt == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle extension source creation attribute
|
|
||||||
if (api.getAttributeValue(elt, "sse-connect")) {
|
|
||||||
var sseURL = api.getAttributeValue(elt, "sse-connect");
|
|
||||||
if (sseURL == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ensureEventSource(elt, sseURL, retryCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
registerSSE(elt);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureEventSource(elt, url, retryCount) {
|
|
||||||
var source = htmx.createEventSource(url);
|
|
||||||
|
|
||||||
source.onerror = function (err) {
|
|
||||||
// Log an error event
|
|
||||||
api.triggerErrorEvent(elt, "htmx:sseError", { error: err, source });
|
|
||||||
|
|
||||||
// If parent no longer exists in the document, then clean up this EventSource
|
|
||||||
if (maybeCloseSSESource(elt)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, try to reconnect the EventSource
|
|
||||||
if (source.readyState === EventSource.CLOSED) {
|
|
||||||
retryCount = retryCount || 0;
|
|
||||||
retryCount = Math.max(Math.min(retryCount * 2, 128), 1);
|
|
||||||
var timeout = retryCount * 500;
|
|
||||||
window.setTimeout(function () {
|
|
||||||
ensureEventSourceOnElement(elt, retryCount);
|
|
||||||
}, timeout);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
source.onopen = function (evt) {
|
|
||||||
api.triggerEvent(elt, "htmx:sseOpen", { source });
|
|
||||||
|
|
||||||
if (retryCount && retryCount > 0) {
|
|
||||||
const childrenToFix = elt.querySelectorAll(
|
|
||||||
"[sse-swap], [data-sse-swap], [hx-trigger], [data-hx-trigger]",
|
|
||||||
);
|
|
||||||
for (let i = 0; i < childrenToFix.length; i++) {
|
|
||||||
registerSSE(childrenToFix[i]);
|
|
||||||
}
|
|
||||||
// We want to increase the reconnection delay for consecutive failed attempts only
|
|
||||||
retryCount = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
api.getInternalData(elt).sseEventSource = source;
|
|
||||||
|
|
||||||
var closeAttribute = api.getAttributeValue(elt, "sse-close");
|
|
||||||
if (closeAttribute) {
|
|
||||||
// close eventsource when this message is received
|
|
||||||
source.addEventListener(closeAttribute, function () {
|
|
||||||
api.triggerEvent(elt, "htmx:sseClose", {
|
|
||||||
source,
|
|
||||||
type: "message",
|
|
||||||
});
|
|
||||||
source.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* maybeCloseSSESource confirms that the parent element still exists.
|
|
||||||
* If not, then any associated SSE source is closed and the function returns true.
|
|
||||||
*
|
|
||||||
* @param {HTMLElement} elt
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
function maybeCloseSSESource(elt) {
|
|
||||||
if (!api.bodyContains(elt)) {
|
|
||||||
var source = api.getInternalData(elt).sseEventSource;
|
|
||||||
if (source != undefined) {
|
|
||||||
api.triggerEvent(elt, "htmx:sseClose", {
|
|
||||||
source,
|
|
||||||
type: "nodeMissing",
|
|
||||||
});
|
|
||||||
source.close();
|
|
||||||
// source = null
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {HTMLElement} elt
|
|
||||||
* @param {string} content
|
|
||||||
*/
|
|
||||||
function swap(elt, content) {
|
|
||||||
api.withExtensions(elt, function (extension) {
|
|
||||||
content = extension.transformResponse(content, null, elt);
|
|
||||||
});
|
|
||||||
|
|
||||||
var swapSpec = api.getSwapSpecification(elt);
|
|
||||||
var target = api.getTarget(elt);
|
|
||||||
api.swap(target, content, swapSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasEventSource(node) {
|
|
||||||
return api.getInternalData(node).sseEventSource != null;
|
|
||||||
}
|
|
||||||
})();
|
|
|
@ -1,517 +0,0 @@
|
||||||
/*
|
|
||||||
WebSockets Extension
|
|
||||||
============================
|
|
||||||
This extension adds support for WebSockets to htmx. See /www/extensions/ws.md for usage instructions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
/** @type {import("../htmx").HtmxInternalApi} */
|
|
||||||
var api;
|
|
||||||
|
|
||||||
htmx.defineExtension("ws", {
|
|
||||||
/**
|
|
||||||
* init is called once, when this extension is first registered.
|
|
||||||
* @param {import("../htmx").HtmxInternalApi} apiRef
|
|
||||||
*/
|
|
||||||
init: function (apiRef) {
|
|
||||||
// Store reference to internal API
|
|
||||||
api = apiRef;
|
|
||||||
|
|
||||||
// Default function for creating new EventSource objects
|
|
||||||
if (!htmx.createWebSocket) {
|
|
||||||
htmx.createWebSocket = createWebSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default setting for reconnect delay
|
|
||||||
if (!htmx.config.wsReconnectDelay) {
|
|
||||||
htmx.config.wsReconnectDelay = "full-jitter";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* onEvent handles all events passed to this extension.
|
|
||||||
*
|
|
||||||
* @param {string} name
|
|
||||||
* @param {Event} evt
|
|
||||||
*/
|
|
||||||
onEvent: function (name, evt) {
|
|
||||||
var parent = evt.target || evt.detail.elt;
|
|
||||||
switch (name) {
|
|
||||||
// Try to close the socket when elements are removed
|
|
||||||
case "htmx:beforeCleanupElement":
|
|
||||||
var internalData = api.getInternalData(parent);
|
|
||||||
|
|
||||||
if (internalData.webSocket) {
|
|
||||||
internalData.webSocket.close();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Try to create websockets when elements are processed
|
|
||||||
case "htmx:beforeProcessNode":
|
|
||||||
forEach(
|
|
||||||
queryAttributeOnThisOrChildren(parent, "ws-connect"),
|
|
||||||
function (child) {
|
|
||||||
ensureWebSocket(child);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
forEach(
|
|
||||||
queryAttributeOnThisOrChildren(parent, "ws-send"),
|
|
||||||
function (child) {
|
|
||||||
ensureWebSocketSend(child);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
function splitOnWhitespace(trigger) {
|
|
||||||
return trigger.trim().split(/\s+/);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLegacyWebsocketURL(elt) {
|
|
||||||
var legacySSEValue = api.getAttributeValue(elt, "hx-ws");
|
|
||||||
if (legacySSEValue) {
|
|
||||||
var values = splitOnWhitespace(legacySSEValue);
|
|
||||||
for (var i = 0; i < values.length; i++) {
|
|
||||||
var value = values[i].split(/:(.+)/);
|
|
||||||
if (value[0] === "connect") {
|
|
||||||
return value[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ensureWebSocket creates a new WebSocket on the designated element, using
|
|
||||||
* the element's "ws-connect" attribute.
|
|
||||||
* @param {HTMLElement} socketElt
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function ensureWebSocket(socketElt) {
|
|
||||||
// If the element containing the WebSocket connection no longer exists, then
|
|
||||||
// do not connect/reconnect the WebSocket.
|
|
||||||
if (!api.bodyContains(socketElt)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the source straight from the element's value
|
|
||||||
var wssSource = api.getAttributeValue(socketElt, "ws-connect");
|
|
||||||
|
|
||||||
if (wssSource == null || wssSource === "") {
|
|
||||||
var legacySource = getLegacyWebsocketURL(socketElt);
|
|
||||||
if (legacySource == null) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
wssSource = legacySource;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Guarantee that the wssSource value is a fully qualified URL
|
|
||||||
if (wssSource.indexOf("/") === 0) {
|
|
||||||
var base_part =
|
|
||||||
location.hostname + (location.port ? ":" + location.port : "");
|
|
||||||
if (location.protocol === "https:") {
|
|
||||||
wssSource = "wss://" + base_part + wssSource;
|
|
||||||
} else if (location.protocol === "http:") {
|
|
||||||
wssSource = "ws://" + base_part + wssSource;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var socketWrapper = createWebsocketWrapper(socketElt, function () {
|
|
||||||
return htmx.createWebSocket(wssSource);
|
|
||||||
});
|
|
||||||
|
|
||||||
socketWrapper.addEventListener("message", function (event) {
|
|
||||||
if (maybeCloseWebSocketSource(socketElt)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = event.data;
|
|
||||||
if (
|
|
||||||
!api.triggerEvent(socketElt, "htmx:wsBeforeMessage", {
|
|
||||||
message: response,
|
|
||||||
socketWrapper: socketWrapper.publicInterface,
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
api.withExtensions(socketElt, function (extension) {
|
|
||||||
response = extension.transformResponse(response, null, socketElt);
|
|
||||||
});
|
|
||||||
|
|
||||||
var settleInfo = api.makeSettleInfo(socketElt);
|
|
||||||
var fragment = api.makeFragment(response);
|
|
||||||
|
|
||||||
if (fragment.children.length) {
|
|
||||||
var children = Array.from(fragment.children);
|
|
||||||
for (var i = 0; i < children.length; i++) {
|
|
||||||
api.oobSwap(
|
|
||||||
api.getAttributeValue(children[i], "hx-swap-oob") || "true",
|
|
||||||
children[i],
|
|
||||||
settleInfo,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
api.settleImmediately(settleInfo.tasks);
|
|
||||||
api.triggerEvent(socketElt, "htmx:wsAfterMessage", {
|
|
||||||
message: response,
|
|
||||||
socketWrapper: socketWrapper.publicInterface,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Put the WebSocket into the HTML Element's custom data.
|
|
||||||
api.getInternalData(socketElt).webSocket = socketWrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} WebSocketWrapper
|
|
||||||
* @property {WebSocket} socket
|
|
||||||
* @property {Array<{message: string, sendElt: Element}>} messageQueue
|
|
||||||
* @property {number} retryCount
|
|
||||||
* @property {(message: string, sendElt: Element) => void} sendImmediately sendImmediately sends message regardless of websocket connection state
|
|
||||||
* @property {(message: string, sendElt: Element) => void} send
|
|
||||||
* @property {(event: string, handler: Function) => void} addEventListener
|
|
||||||
* @property {() => void} handleQueuedMessages
|
|
||||||
* @property {() => void} init
|
|
||||||
* @property {() => void} close
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param socketElt
|
|
||||||
* @param socketFunc
|
|
||||||
* @returns {WebSocketWrapper}
|
|
||||||
*/
|
|
||||||
function createWebsocketWrapper(socketElt, socketFunc) {
|
|
||||||
var wrapper = {
|
|
||||||
socket: null,
|
|
||||||
messageQueue: [],
|
|
||||||
retryCount: 0,
|
|
||||||
|
|
||||||
/** @type {Object<string, Function[]>} */
|
|
||||||
events: {},
|
|
||||||
|
|
||||||
addEventListener: function (event, handler) {
|
|
||||||
if (this.socket) {
|
|
||||||
this.socket.addEventListener(event, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.events[event]) {
|
|
||||||
this.events[event] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
this.events[event].push(handler);
|
|
||||||
},
|
|
||||||
|
|
||||||
sendImmediately: function (message, sendElt) {
|
|
||||||
if (!this.socket) {
|
|
||||||
api.triggerErrorEvent();
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!sendElt ||
|
|
||||||
api.triggerEvent(sendElt, "htmx:wsBeforeSend", {
|
|
||||||
message,
|
|
||||||
socketWrapper: this.publicInterface,
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
this.socket.send(message);
|
|
||||||
sendElt &&
|
|
||||||
api.triggerEvent(sendElt, "htmx:wsAfterSend", {
|
|
||||||
message,
|
|
||||||
socketWrapper: this.publicInterface,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
send: function (message, sendElt) {
|
|
||||||
if (this.socket.readyState !== this.socket.OPEN) {
|
|
||||||
this.messageQueue.push({ message, sendElt });
|
|
||||||
} else {
|
|
||||||
this.sendImmediately(message, sendElt);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleQueuedMessages: function () {
|
|
||||||
while (this.messageQueue.length > 0) {
|
|
||||||
var queuedItem = this.messageQueue[0];
|
|
||||||
if (this.socket.readyState === this.socket.OPEN) {
|
|
||||||
this.sendImmediately(queuedItem.message, queuedItem.sendElt);
|
|
||||||
this.messageQueue.shift();
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
init: function () {
|
|
||||||
if (this.socket && this.socket.readyState === this.socket.OPEN) {
|
|
||||||
// Close discarded socket
|
|
||||||
this.socket.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new WebSocket and event handlers
|
|
||||||
/** @type {WebSocket} */
|
|
||||||
var socket = socketFunc();
|
|
||||||
|
|
||||||
// The event.type detail is added for interface conformance with the
|
|
||||||
// other two lifecycle events (open and close) so a single handler method
|
|
||||||
// can handle them polymorphically, if required.
|
|
||||||
api.triggerEvent(socketElt, "htmx:wsConnecting", {
|
|
||||||
event: { type: "connecting" },
|
|
||||||
});
|
|
||||||
|
|
||||||
this.socket = socket;
|
|
||||||
|
|
||||||
socket.onopen = function (e) {
|
|
||||||
wrapper.retryCount = 0;
|
|
||||||
api.triggerEvent(socketElt, "htmx:wsOpen", {
|
|
||||||
event: e,
|
|
||||||
socketWrapper: wrapper.publicInterface,
|
|
||||||
});
|
|
||||||
wrapper.handleQueuedMessages();
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.onclose = function (e) {
|
|
||||||
// If socket should not be connected, stop further attempts to establish connection
|
|
||||||
// If Abnormal Closure/Service Restart/Try Again Later, then set a timer to reconnect after a pause.
|
|
||||||
if (
|
|
||||||
!maybeCloseWebSocketSource(socketElt) &&
|
|
||||||
[1006, 1012, 1013].indexOf(e.code) >= 0
|
|
||||||
) {
|
|
||||||
var delay = getWebSocketReconnectDelay(wrapper.retryCount);
|
|
||||||
setTimeout(function () {
|
|
||||||
wrapper.retryCount += 1;
|
|
||||||
wrapper.init();
|
|
||||||
}, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify client code that connection has been closed. Client code can inspect `event` field
|
|
||||||
// to determine whether closure has been valid or abnormal
|
|
||||||
api.triggerEvent(socketElt, "htmx:wsClose", {
|
|
||||||
event: e,
|
|
||||||
socketWrapper: wrapper.publicInterface,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.onerror = function (e) {
|
|
||||||
api.triggerErrorEvent(socketElt, "htmx:wsError", {
|
|
||||||
error: e,
|
|
||||||
socketWrapper: wrapper,
|
|
||||||
});
|
|
||||||
maybeCloseWebSocketSource(socketElt);
|
|
||||||
};
|
|
||||||
|
|
||||||
var events = this.events;
|
|
||||||
Object.keys(events).forEach(function (k) {
|
|
||||||
events[k].forEach(function (e) {
|
|
||||||
socket.addEventListener(k, e);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
close: function () {
|
|
||||||
this.socket.close();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
wrapper.init();
|
|
||||||
|
|
||||||
wrapper.publicInterface = {
|
|
||||||
send: wrapper.send.bind(wrapper),
|
|
||||||
sendImmediately: wrapper.sendImmediately.bind(wrapper),
|
|
||||||
queue: wrapper.messageQueue,
|
|
||||||
};
|
|
||||||
|
|
||||||
return wrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ensureWebSocketSend attaches trigger handles to elements with
|
|
||||||
* "ws-send" attribute
|
|
||||||
* @param {HTMLElement} elt
|
|
||||||
*/
|
|
||||||
function ensureWebSocketSend(elt) {
|
|
||||||
var legacyAttribute = api.getAttributeValue(elt, "hx-ws");
|
|
||||||
if (legacyAttribute && legacyAttribute !== "send") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var webSocketParent = api.getClosestMatch(elt, hasWebSocket);
|
|
||||||
processWebSocketSend(webSocketParent, elt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* hasWebSocket function checks if a node has webSocket instance attached
|
|
||||||
* @param {HTMLElement} node
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function hasWebSocket(node) {
|
|
||||||
return api.getInternalData(node).webSocket != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* processWebSocketSend adds event listeners to the <form> element so that
|
|
||||||
* messages can be sent to the WebSocket server when the form is submitted.
|
|
||||||
* @param {HTMLElement} socketElt
|
|
||||||
* @param {HTMLElement} sendElt
|
|
||||||
*/
|
|
||||||
function processWebSocketSend(socketElt, sendElt) {
|
|
||||||
var nodeData = api.getInternalData(sendElt);
|
|
||||||
var triggerSpecs = api.getTriggerSpecs(sendElt);
|
|
||||||
triggerSpecs.forEach(function (ts) {
|
|
||||||
api.addTriggerHandler(sendElt, ts, nodeData, function (elt, evt) {
|
|
||||||
if (maybeCloseWebSocketSource(socketElt)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {WebSocketWrapper} */
|
|
||||||
var socketWrapper = api.getInternalData(socketElt).webSocket;
|
|
||||||
var headers = api.getHeaders(sendElt, api.getTarget(sendElt));
|
|
||||||
var results = api.getInputValues(sendElt, "post");
|
|
||||||
var errors = results.errors;
|
|
||||||
var rawParameters = Object.assign({}, results.values);
|
|
||||||
var expressionVars = api.getExpressionVars(sendElt);
|
|
||||||
var allParameters = api.mergeObjects(rawParameters, expressionVars);
|
|
||||||
var filteredParameters = api.filterValues(allParameters, sendElt);
|
|
||||||
|
|
||||||
var sendConfig = {
|
|
||||||
parameters: filteredParameters,
|
|
||||||
unfilteredParameters: allParameters,
|
|
||||||
headers,
|
|
||||||
errors,
|
|
||||||
|
|
||||||
triggeringEvent: evt,
|
|
||||||
messageBody: undefined,
|
|
||||||
socketWrapper: socketWrapper.publicInterface,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!api.triggerEvent(elt, "htmx:wsConfigSend", sendConfig)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errors && errors.length > 0) {
|
|
||||||
api.triggerEvent(elt, "htmx:validation:halted", errors);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var body = sendConfig.messageBody;
|
|
||||||
if (body === undefined) {
|
|
||||||
var toSend = Object.assign({}, sendConfig.parameters);
|
|
||||||
if (sendConfig.headers) {
|
|
||||||
toSend.HEADERS = headers;
|
|
||||||
}
|
|
||||||
body = JSON.stringify(toSend);
|
|
||||||
}
|
|
||||||
|
|
||||||
socketWrapper.send(body, elt);
|
|
||||||
|
|
||||||
if (evt && api.shouldCancel(evt, elt)) {
|
|
||||||
evt.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getWebSocketReconnectDelay is the default easing function for WebSocket reconnects.
|
|
||||||
* @param {number} retryCount // The number of retries that have already taken place
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
function getWebSocketReconnectDelay(retryCount) {
|
|
||||||
/** @type {"full-jitter" | ((retryCount:number) => number)} */
|
|
||||||
var delay = htmx.config.wsReconnectDelay;
|
|
||||||
if (typeof delay === "function") {
|
|
||||||
return delay(retryCount);
|
|
||||||
}
|
|
||||||
if (delay === "full-jitter") {
|
|
||||||
var exp = Math.min(retryCount, 6);
|
|
||||||
var maxDelay = 1000 * Math.pow(2, exp);
|
|
||||||
return maxDelay * Math.random();
|
|
||||||
}
|
|
||||||
|
|
||||||
logError(
|
|
||||||
'htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* maybeCloseWebSocketSource checks to the if the element that created the WebSocket
|
|
||||||
* still exists in the DOM. If NOT, then the WebSocket is closed and this function
|
|
||||||
* returns TRUE. If the element DOES EXIST, then no action is taken, and this function
|
|
||||||
* returns FALSE.
|
|
||||||
*
|
|
||||||
* @param {*} elt
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function maybeCloseWebSocketSource(elt) {
|
|
||||||
if (!api.bodyContains(elt)) {
|
|
||||||
var internalData = api.getInternalData(elt);
|
|
||||||
if (internalData.webSocket) {
|
|
||||||
internalData.webSocket.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* createWebSocket is the default method for creating new WebSocket objects.
|
|
||||||
* it is hoisted into htmx.createWebSocket to be overridden by the user, if needed.
|
|
||||||
*
|
|
||||||
* @param {string} url
|
|
||||||
* @returns WebSocket
|
|
||||||
*/
|
|
||||||
function createWebSocket(url) {
|
|
||||||
var sock = new WebSocket(url, []);
|
|
||||||
sock.binaryType = htmx.config.wsBinaryType;
|
|
||||||
return sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* queryAttributeOnThisOrChildren returns all nodes that contain the requested attributeName, INCLUDING THE PROVIDED ROOT ELEMENT.
|
|
||||||
*
|
|
||||||
* @param {HTMLElement} elt
|
|
||||||
* @param {string} attributeName
|
|
||||||
*/
|
|
||||||
function queryAttributeOnThisOrChildren(elt, attributeName) {
|
|
||||||
var result = [];
|
|
||||||
|
|
||||||
// If the parent element also contains the requested attribute, then add it to the results too.
|
|
||||||
if (
|
|
||||||
api.hasAttribute(elt, attributeName) ||
|
|
||||||
api.hasAttribute(elt, "hx-ws")
|
|
||||||
) {
|
|
||||||
result.push(elt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search all child nodes that match the requested attribute
|
|
||||||
elt
|
|
||||||
.querySelectorAll(
|
|
||||||
"[" +
|
|
||||||
attributeName +
|
|
||||||
"], [data-" +
|
|
||||||
attributeName +
|
|
||||||
"], [data-hx-ws], [hx-ws]",
|
|
||||||
)
|
|
||||||
.forEach(function (node) {
|
|
||||||
result.push(node);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @template T
|
|
||||||
* @param {T[]} arr
|
|
||||||
* @param {(T) => void} func
|
|
||||||
*/
|
|
||||||
function forEach(arr, func) {
|
|
||||||
if (arr) {
|
|
||||||
for (var i = 0; i < arr.length; i++) {
|
|
||||||
func(arr[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
File diff suppressed because one or more lines are too long
12
routes/_404.tsx
Normal file
12
routes/_404.tsx
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { Head } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
export default function Error404() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>404 - Page not found</title>
|
||||||
|
</Head>
|
||||||
|
<h1>404 Page Not Found</h1>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
17
routes/_app.tsx
Normal file
17
routes/_app.tsx
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { type PageProps } from "$fresh/server.ts";
|
||||||
|
export default function App({ Component }: PageProps) {
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Atridad Lahiji</title>
|
||||||
|
<link rel="stylesheet" href="/styles.css" />
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico"></link>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<Component />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
56
routes/_layout.tsx
Normal file
56
routes/_layout.tsx
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
// routes/_layout.tsx
|
||||||
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
import { Head } from "$fresh/runtime.ts";
|
||||||
|
import { LuCodeXml, LuHouse, LuNotebookPen } from "@preact-icons/lu";
|
||||||
|
|
||||||
|
export default function Layout({ Component, url }: PageProps) {
|
||||||
|
const currentPath = url.pathname;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<title>Atridad Lahiji</title>
|
||||||
|
</Head>
|
||||||
|
<body class="flex flex-col min-h-screen">
|
||||||
|
<main class="flex-grow flex flex-col gap-4 items-center justify-center">
|
||||||
|
<Component />
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<div class="fixed bottom-4 left-1/2 transform -translate-x-1/2 z-20">
|
||||||
|
<ul class="menu menu-horizontal bg-base-200 rounded-box p-2 shadow-lg gap-2">
|
||||||
|
<li>
|
||||||
|
<a href="/" class={currentPath === "/" ? "menu-active" : ""}>
|
||||||
|
<div class="tooltip" data-tip="Home">
|
||||||
|
<LuHouse class="text-xl" />
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href="/posts"
|
||||||
|
class={currentPath.startsWith("/posts") ? "menu-active" : ""}
|
||||||
|
>
|
||||||
|
<div class="tooltip" data-tip="Posts">
|
||||||
|
<LuNotebookPen class="text-xl" />
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href="/projects"
|
||||||
|
class={currentPath.startsWith("/projects") ? "menu-active" : ""}
|
||||||
|
>
|
||||||
|
<div class="tooltip" data-tip="Projects">
|
||||||
|
<LuCodeXml class="text-xl" />
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
21
routes/api/joke.ts
Normal file
21
routes/api/joke.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
// Jokes courtesy of https://punsandoneliners.com/randomness/programmer-jokes/
|
||||||
|
const JOKES = [
|
||||||
|
"Why do Java developers often wear glasses? They can't C#.",
|
||||||
|
"A SQL query walks into a bar, goes up to two tables and says “can I join you?”",
|
||||||
|
"Wasn't hard to crack Forrest Gump's password. 1forrest1.",
|
||||||
|
"I love pressing the F5 key. It's refreshing.",
|
||||||
|
"Called IT support and a chap from Australia came to fix my network connection. I asked “Do you come from a LAN down under?”",
|
||||||
|
"There are 10 types of people in the world. Those who understand binary and those who don't.",
|
||||||
|
"Why are assembly programmers often wet? They work below C level.",
|
||||||
|
"My favourite computer based band is the Black IPs.",
|
||||||
|
"What programme do you use to predict the music tastes of former US presidential candidates? An Al Gore Rhythm.",
|
||||||
|
"An SEO expert walked into a bar, pub, inn, tavern, hostelry, public house.",
|
||||||
|
];
|
||||||
|
|
||||||
|
export const handler = (_req: Request, _ctx: FreshContext): Response => {
|
||||||
|
const randomIndex = Math.floor(Math.random() * JOKES.length);
|
||||||
|
const body = JOKES[randomIndex];
|
||||||
|
return new Response(body);
|
||||||
|
};
|
30
routes/index.tsx
Normal file
30
routes/index.tsx
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import HomeButtonLinks from "../components/HomeButtonLinks.tsx";
|
||||||
|
import SocialLinks from "../components/SocialLinks.tsx";
|
||||||
|
import TechLinks from "../components/TechLinks.tsx";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<img
|
||||||
|
src="/logo.webp"
|
||||||
|
alt="A drawing of Atridad Lahiji by Shelze!"
|
||||||
|
height={200}
|
||||||
|
width={200}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1 class="bg-gradient-to-r from-primary via-secondary to-accent bg-clip-text text-transparent text-6xl font-bold">
|
||||||
|
Atridad Lahiji
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<h2 class="text-2xl font-bold">Places I Exist:</h2>
|
||||||
|
|
||||||
|
<SocialLinks />
|
||||||
|
|
||||||
|
<h2 class="text-2xl font-bold">Stuff I Use:</h2>
|
||||||
|
|
||||||
|
<TechLinks />
|
||||||
|
|
||||||
|
<HomeButtonLinks />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
83
routes/post/[slug].tsx
Normal file
83
routes/post/[slug].tsx
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
import { CSS, render } from "@deno/gfm";
|
||||||
|
import { Head } from "$fresh/runtime.ts";
|
||||||
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
import { getPost, Post } from "../../lib/posts.ts";
|
||||||
|
import { LuClock } from "@preact-icons/lu";
|
||||||
|
|
||||||
|
export const handler: Handlers<Post> = {
|
||||||
|
async GET(_req, ctx) {
|
||||||
|
try {
|
||||||
|
const post = await getPost(ctx.params.slug);
|
||||||
|
return post.publishedAt ? ctx.render(post) : ctx.renderNotFound();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return ctx.renderNotFound();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function PostPage(props: PageProps<Post>) {
|
||||||
|
const post = props.data;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<style dangerouslySetInnerHTML={{ __html: CSS }} />
|
||||||
|
</Head>
|
||||||
|
<div class="min-h-screen p-4 md:p-8">
|
||||||
|
<div class="max-w-3xl mx-auto">
|
||||||
|
<div class="p-4 md:p-8">
|
||||||
|
{/* Header section */}
|
||||||
|
<h1 class="text-4xl md:text-5xl font-bold text-primary mb-6">
|
||||||
|
{post.title}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-4 mb-6">
|
||||||
|
{/* Date with clock icon */}
|
||||||
|
<div class="flex items-center flex-row gap-2 text-base-content opacity-75">
|
||||||
|
<LuClock />
|
||||||
|
<time>
|
||||||
|
{post.publishedAt!.toLocaleDateString("en-us", {
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
})}
|
||||||
|
</time>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Back button */}
|
||||||
|
<a href="/posts" class="btn btn-outline btn-primary btn-sm">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
class="h-5 w-5 mr-1"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M11 17l-5-5m0 0l5-5m-5 5h12"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
Back
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Divider line */}
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
{/* Content section */}
|
||||||
|
<div
|
||||||
|
class="max-w-none prose"
|
||||||
|
data-color-mode="dark"
|
||||||
|
data-dark-theme="dark"
|
||||||
|
dangerouslySetInnerHTML={{ __html: render(post.content) }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
24
routes/posts.tsx
Normal file
24
routes/posts.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||||
|
import { getPosts, Post } from "../lib/posts.ts";
|
||||||
|
import PostCard from "../components/PostCard.tsx";
|
||||||
|
|
||||||
|
export const handler: Handlers<Post[]> = {
|
||||||
|
async GET(_req, ctx) {
|
||||||
|
const posts = await getPosts();
|
||||||
|
return ctx.render(posts);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function PostsPage(props: PageProps<Post[]>) {
|
||||||
|
const posts = props.data;
|
||||||
|
return (
|
||||||
|
<div class="min-h-screen p-4 sm:p-8">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-bold text-primary mb-6 sm:mb-8 text-center">
|
||||||
|
Posts
|
||||||
|
</h1>
|
||||||
|
<div class="flex flex-row flex-wrap justify-center gap-4 sm:gap-6 max-w-6xl mx-auto">
|
||||||
|
{posts.map((post) => <PostCard key={post.slug} post={post} />)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
60
routes/projects.tsx
Normal file
60
routes/projects.tsx
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import ProjectCard from "../components/ProjectCard.tsx";
|
||||||
|
|
||||||
|
interface Project {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
link: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProjectsPage() {
|
||||||
|
const projects: Project[] = [
|
||||||
|
{
|
||||||
|
id: "bluesky-pds-manager",
|
||||||
|
name: "BlueSky PDS Manager",
|
||||||
|
description:
|
||||||
|
"A web-based BlueSky PDS Manager. Manage your invite codes and users with a simple web UI.",
|
||||||
|
link: "https://pdsman.atri.dad",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "pollo",
|
||||||
|
name: "Pollo",
|
||||||
|
description: "A dead-simple real-time voting tool.",
|
||||||
|
link: "https://git.atri.dad/atridad/pollo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "goth-stack",
|
||||||
|
name: "GOTH Stack",
|
||||||
|
description:
|
||||||
|
"🚀 A Web Application Template Powered by HTMX + Go + Tailwind 🚀",
|
||||||
|
link: "https://git.atri.dad/atridad/goth.stack",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "himbot",
|
||||||
|
name: "Himbot",
|
||||||
|
description:
|
||||||
|
"A discord bot written in Go. Loosly named after my username online (HimbothySwaggins).",
|
||||||
|
link: "https://git.atri.dad/atridad/himbot",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "loadr",
|
||||||
|
name: "loadr",
|
||||||
|
description:
|
||||||
|
"A lightweight REST load testing tool with robust support for different verbs, token auth, and performance reports.",
|
||||||
|
link: "https://git.atri.dad/atridad/loadr",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="min-h-screen p-4 sm:p-8">
|
||||||
|
<h1 class="text-3xl sm:text-4xl font-bold text-secondary mb-6 sm:mb-8 text-center">
|
||||||
|
Projects
|
||||||
|
</h1>
|
||||||
|
<div class="flex flex-row flex-wrap justify-center gap-4 sm:gap-6 max-w-6xl mx-auto">
|
||||||
|
{projects.map((project) => (
|
||||||
|
<ProjectCard key={project.id} project={project} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
static/files/Atridad_Lahiji_Resume_Public.pdf
Normal file
BIN
static/files/Atridad_Lahiji_Resume_Public.pdf
Normal file
Binary file not shown.
BIN
static/logo.webp
Normal file
BIN
static/logo.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.5 KiB |
37
static/styles.css
Normal file
37
static/styles.css
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
@import "tailwindcss";
|
||||||
|
@plugin "daisyui";
|
||||||
|
@plugin "@tailwindcss/typography";
|
||||||
|
@plugin "daisyui/theme" {
|
||||||
|
name: "chaoticbisexual";
|
||||||
|
default: true;
|
||||||
|
prefersdark: true;
|
||||||
|
color-scheme: "dark";
|
||||||
|
--color-base-100: oklch(25.33% 0.016 252.42);
|
||||||
|
--color-base-200: oklch(23.26% 0.014 253.1);
|
||||||
|
--color-base-300: oklch(21.15% 0.012 254.09);
|
||||||
|
--color-base-content: oklch(97.807% 0.029 256.847);
|
||||||
|
--color-primary: oklch(65% 0.241 354.308);
|
||||||
|
--color-primary-content: oklch(96% 0.018 272.314);
|
||||||
|
--color-secondary: oklch(60% 0.25 292.717);
|
||||||
|
--color-secondary-content: oklch(94% 0.028 342.258);
|
||||||
|
--color-accent: oklch(78% 0.154 211.53);
|
||||||
|
--color-accent-content: oklch(38% 0.063 188.416);
|
||||||
|
--color-neutral: oklch(40% 0.17 325.612);
|
||||||
|
--color-neutral-content: oklch(92% 0.004 286.32);
|
||||||
|
--color-info: oklch(74% 0.16 232.661);
|
||||||
|
--color-info-content: oklch(29% 0.066 243.157);
|
||||||
|
--color-success: oklch(76% 0.177 163.223);
|
||||||
|
--color-success-content: oklch(37% 0.077 168.94);
|
||||||
|
--color-warning: oklch(82% 0.189 84.429);
|
||||||
|
--color-warning-content: oklch(41% 0.112 45.904);
|
||||||
|
--color-error: oklch(71% 0.194 13.428);
|
||||||
|
--color-error-content: oklch(27% 0.105 12.094);
|
||||||
|
--radius-selector: 1rem;
|
||||||
|
--radius-field: 1rem;
|
||||||
|
--radius-box: 1rem;
|
||||||
|
--size-selector: 0.25rem;
|
||||||
|
--size-field: 0.25rem;
|
||||||
|
--border: 1px;
|
||||||
|
--depth: 1;
|
||||||
|
--noise: 1;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue