im gay
This commit is contained in:
commit
cdee9a9019
|
@ -0,0 +1,26 @@
|
|||
# The directory Mix will write compiled artifacts to.
|
||||
/_build/
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover/
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps/
|
||||
|
||||
# Where third-party dependencies like ExDoc output generated docs.
|
||||
/doc/
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
webgen-*.tar
|
||||
|
||||
# No useful tests are present
|
||||
/test/
|
|
@ -0,0 +1,23 @@
|
|||
# Webgen
|
||||
|
||||
hi this is a very simple program for merging a text file into a webpage
|
||||
|
||||
it was only made for my webbed sight at https://ella.wantscuddl.es/
|
||||
|
||||
## if you for whatever reason want to use this for your own pages
|
||||
|
||||
* first edit mix.exs line 16 to use your desired path
|
||||
* then create a file called "gen-conf" in that directory (use the example-gen-conf file included as an example). the first line is the "base website" that is going to be used.
|
||||
on following lines, write the relative path to files you want to merge into webpages
|
||||
* now you can, in the same directory, create files with the website content
|
||||
* when running the program (open a shell, cd to here and type `mix run`) it should save the files as `$file`.html
|
||||
|
||||
## help what are the $ things??
|
||||
|
||||
* $title - the title, which is the first line of content files
|
||||
* $first - the first line of the page, with tags stripped away
|
||||
* $file - the relative path without `index/` as the first characters
|
||||
* $content - the page body
|
||||
refer to example-gen-conf for an example
|
||||
|
||||
if something here does not make sense, you can ask me for help, preferably at https://hellsite.site/@ella
|
|
@ -0,0 +1,2 @@
|
|||
<!DOCTYPE html><html><head><meta name="description" content="$first"/><meta property="og:description" content="$first"/><meta property="og:title" content="$title"/><meta property="og:type" content="website"/><meta property="og:url" content="https://ella.wantscuddl.es/$file"/><title>$title</title></head><body><h1>$title</h1><p>$content</p></body></html>
|
||||
index/index
|
|
@ -0,0 +1,40 @@
|
|||
defmodule Merger do
|
||||
def child_spec(opts) do
|
||||
%{
|
||||
id: __MODULE__,
|
||||
start: {__MODULE__, :start_link, [opts]},
|
||||
type: :supervisor,
|
||||
restart: :temporary,
|
||||
shutdown: 500
|
||||
}
|
||||
end
|
||||
def start_link(opts) do
|
||||
Supervisor.start_link(__MODULE__, :ok, opts)
|
||||
end
|
||||
def init(:ok) do
|
||||
File.cd(Application.fetch_env!(:webgen, :root))
|
||||
[merg | file] = String.split(File.read!("./gen-conf"), "\n")
|
||||
Enum.each(file, fn i ->
|
||||
if String.at(i, 0) != "#" do
|
||||
docomp(i, merg)
|
||||
end
|
||||
end)
|
||||
Supervisor.init([], [strategy: :one_for_one])
|
||||
end
|
||||
def docomp(file, merg) do
|
||||
[title, content] = String.split(File.read!(file), "\n", parts: 2)
|
||||
first = String.replace(String.replace(content, ~r/\n.*/s, "", global: false), ~r/<.*?>/, "")
|
||||
file = String.replace(file, ~r/blogindex$/, "")
|
||||
url = String.replace(String.replace(file, ~r/^index\//, ""), ~r/^inde?x$/, "");
|
||||
File.write([file, ".html"], String.replace(
|
||||
String.replace(
|
||||
String.replace(
|
||||
String.replace(merg, "$file", url),
|
||||
"$first", first),
|
||||
"$title", title),
|
||||
"$content", String.replace(
|
||||
String.replace(content, "\n\n", "</p><p>"), "\n", "<br/>"
|
||||
)
|
||||
))
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
defmodule Webgen do
|
||||
def start(_type, _args) do
|
||||
Supervisor.start_link([{Merger, []}], [strategy: :one_for_one])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
defmodule Webgen.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :webgen,
|
||||
version: "0.1.0",
|
||||
elixir: "~> 1.10",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
def application do
|
||||
[
|
||||
env: [root: "/home/ella/website/"],
|
||||
mod: {Webgen, []}, extra_applications: [:logger]
|
||||
]
|
||||
end
|
||||
|
||||
defp deps do [] end
|
||||
end
|
Loading…
Reference in New Issue