From cdee9a90190328668e0ab34b6af8000c309176a1 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 18 Sep 2020 18:54:48 +0200 Subject: [PATCH] im gay --- .gitignore | 26 ++++++++++++++++++++++++++ README.md | 23 +++++++++++++++++++++++ example-gen-conf | 2 ++ lib/merger.ex | 40 ++++++++++++++++++++++++++++++++++++++++ lib/webgen.ex | 5 +++++ mix.exs | 22 ++++++++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 example-gen-conf create mode 100644 lib/merger.ex create mode 100644 lib/webgen.ex create mode 100644 mix.exs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16e326c --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e479a2a --- /dev/null +++ b/README.md @@ -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 diff --git a/example-gen-conf b/example-gen-conf new file mode 100644 index 0000000..8719093 --- /dev/null +++ b/example-gen-conf @@ -0,0 +1,2 @@ +$title

$title

$content

+index/index \ No newline at end of file diff --git a/lib/merger.ex b/lib/merger.ex new file mode 100644 index 0000000..0d31920 --- /dev/null +++ b/lib/merger.ex @@ -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", "

"), "\n", "
" + ) + )) + end +end \ No newline at end of file diff --git a/lib/webgen.ex b/lib/webgen.ex new file mode 100644 index 0000000..db6d6e3 --- /dev/null +++ b/lib/webgen.ex @@ -0,0 +1,5 @@ +defmodule Webgen do + def start(_type, _args) do + Supervisor.start_link([{Merger, []}], [strategy: :one_for_one]) + end +end diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..3f0dd82 --- /dev/null +++ b/mix.exs @@ -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