From 13b1ce234a27f8a64492a7a0b88c76adca258817 Mon Sep 17 00:00:00 2001 From: Celeste Date: Sun, 19 Sep 2021 19:35:36 +0100 Subject: [PATCH] Add da files --- .gitignore | 3 + build.sh | 4 ++ init.sh | 33 +++++++++++ main.rb | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++ populate.sh | 3 + 5 files changed, 201 insertions(+) create mode 100644 .gitignore create mode 100644 build.sh create mode 100644 init.sh create mode 100644 main.rb create mode 100644 populate.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80dcac1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/themes +/input +/output diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..84218b9 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh +rm -r output/* +ruby main.rb +echo 'Website built.' diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..9160432 --- /dev/null +++ b/init.sh @@ -0,0 +1,33 @@ +#!/bin/sh +echo "Welcome to the ewfm automagic" +echo "website setter-upper wizard!!" + +echo "First, let's start by creating input/ and the default index.md file." +echo . +mkdir input +touch input/index.md +echo "Your website!" | tee -a input/index.md +echo "## Hello, world!" | tee -a input/index.md +echo "Welcome to ewfm!" | tee -a input/index.md +echo . +echo "Done! Now let's configure your site.conf file!" + +touch input/site.conf + +echo "What is your website's domain?" +read domain +echo $domain | tee -a input/site.conf + +echo "What is your website's name?" +echo . +read name +echo $name | tee -a input/site.conf + +echo "What theme would you like to use? (If in doubt, type linear-base or 3box-base)" +echo . +read theme +echo $theme | tee -a input/site.conf + +echo "All done!" +echo "If you haven't already read the docs at ewfm.colean.cc/docs" +echo "and run populate.sh to download all the ewfm themes!" diff --git a/main.rb b/main.rb new file mode 100644 index 0000000..3d0b82d --- /dev/null +++ b/main.rb @@ -0,0 +1,158 @@ +require 'redcarpet' +require 'date' + +site = IO.readlines("input/site.conf", chomp: true) +site_domain = site[0] +site_name = site[1] +theme = site[2] + +directory = Dir["input/*/"] +everything = Dir["input/**/*.md"] +workspace = Dir["input/*.md"] +prelim = Dir["input/**/*.*"] +base = Dir["input/**/"] +files = [] +structure = [] + +workspace.push(*everything) + +themes_fold = "themes/" +theme_dir = themes_fold + theme + "/" + +protocol = "http://" + +da = ["home "] +dp = ["

home

"] +dsa = ["/ "] +dsp = ["

/

"] + +Dir.mkdir "output/ewfm_theme" + +dist_files = Dir[theme_dir + "dist/*"] +puts dist_files +for file in dist_files + string = File.read(file) + + handle = file + + prefix = theme_dir + "dist/" + handle[prefix]= "output/ewfm_theme/" + + IO.write(handle, string) +end + +for string in base + if string != "input/" + structure.append(string) + end +end + +for string in prelim + if not string.include? ".md" + files.append(string) + end +end + +for file in directory + file1 = "/" + file + file1["input/"]= "" + file2 = file1[1..-1] + file2["/"]= "" + da.append("" + file2 + " ") + dp.append("

" + file2 + "

") + dsa.append("" + file2 + "/ ") + dsp.append("

" + file2 + "/

") +end + +for file in structure + handle = file + handle["input/"]= "" + + comb = "output/" + handle + Dir.mkdir comb unless Dir.exists? comb +end + +for file in files + handle = File.read(file) + + output = file + output["input"]= "output" + IO.write(output, handle) +end + +def scope + yield +end + +for file in workspace + text = File.read(file) + template = File.read(theme_dir + "template.html") + + product = template + + puts file + + renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, fenced_code_blocks: true, strikethrough: true, underline: true, space_after_headers: true) + lines = text.lines + rest_of_content = lines[1..-1] + raw_content = rest_of_content.join() + title = lines[0] + + content = renderer.render(raw_content) + + if product.include? "{SITE_NAME}" + product["{SITE_NAME}"]= site_name + end + + if product.include? "{SITE_DOMAIN}" + product["{SITE_DOMAIN}"]= site_domain + end + + if product.include? "{PAGE_TITLE}" + product["{PAGE_TITLE}"]= title + end + + if product.include? "{DIRECTORY_A}" + product["{DIRECTORY_A}"]= da.join() + end + + if product.include? "{DIRECTORY_P}" + product["{DIRECTORY_P}"]= dp.join() + end + + if product.include? "{DIRECTORY_SLASH_A}" + product["{DIRECTORY_SLASH_A}"]= dsa.join() + end + + if product.include? "{DIRECTORY_SLASH_P}" + product["{DIRECTORY_SLASH_P}"]= dsp.join() + end + + if product.include? "{PAGE_CONTENT}" + product["{PAGE_CONTENT}"]= content + end + + if raw_content.include? "$EWFM$" + product["$EWFM$"]= "

This page has been generated by ewfm using the " + theme + " theme!

" + end + + if raw_content.include? "$THEME$" + product["$THEME$"]= theme + end + + if raw_content.include? "$TIME$" + time = DateTime.now + cdt = time.strftime "%d/%m/%Y %H:%M:%S" + product["$TIME$"]= cdt + end + + if raw_content.include? "$RUBY$" + product["$RUBY$"]= RUBY_VERSION + end + + handle = file + handle["input"]= "output" + handle[".md"]= ".html" + IO.write(handle, product) +end + diff --git a/populate.sh b/populate.sh new file mode 100644 index 0000000..735f257 --- /dev/null +++ b/populate.sh @@ -0,0 +1,3 @@ +#!/bin/sh +git clone https://gitlab.com/threeoh6000/ewfm-themes.git +mv ewfm-themes/ themes/