From 07a884fcb6d1579ec455b3a8f82578d2fb4e5d00 Mon Sep 17 00:00:00 2001 From: Kyle Bowman Date: Mon, 16 Sep 2024 19:59:29 -0400 Subject: [PATCH] Basic static site generator. --- Makefile | 27 ++ _static/css/normalize.css | 461 +++++++++++++++++++++++++++++++++++ _static/css/space-sakura.css | 207 ++++++++++++++++ _static/demo.html | 209 ++++++++++++++++ _static/templates/base.html | 40 +++ build/note1 | 21 ++ build/note2 | 21 ++ experiments.md | 88 +++++++ link-dependencies.py | 86 +++++++ src/note1.md | 6 + src/note2.md | 6 + 11 files changed, 1172 insertions(+) create mode 100644 Makefile create mode 100644 _static/css/normalize.css create mode 100644 _static/css/space-sakura.css create mode 100644 _static/demo.html create mode 100644 _static/templates/base.html create mode 100644 build/note1 create mode 100644 build/note2 create mode 100644 experiments.md create mode 100644 link-dependencies.py create mode 100644 src/note1.md create mode 100644 src/note2.md diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a657707 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +SRC_DIR := src +BUILD_DIR := build + +MARKDOWN_FILES := $(wildcard $(SRC_DIR)/*.md) +HTML_FILES := $(patsubst $(SRC_DIR)/%.md, $(BUILD_DIR)/%, $(MARKDOWN_FILES)) + +.PHONY: all clean + +all: $(HTML_FILES) + +# Create the build directory if it doesn't exist +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +# Build HTML file from Markdown +$(BUILD_DIR)/%: $(SRC_DIR)/%.md | $(BUILD_DIR) + pandoc \ + --from=markdown+wikilinks_title_before_pipe \ + --to=html5 \ + --standalone \ + --template=_static/templates/base.html \ + --output=$@ $< + +# Clean up generated HTML files +clean: + rm -rf $(BUILD_DIR) + diff --git a/_static/css/normalize.css b/_static/css/normalize.css new file mode 100644 index 0000000..9b77e0e --- /dev/null +++ b/_static/css/normalize.css @@ -0,0 +1,461 @@ +/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */ + +/** + * 1. Change the default font family in all browsers (opinionated). + * 2. Correct the line height in all browsers. + * 3. Prevent adjustments of font size after orientation changes in + * IE on Windows Phone and in iOS. + */ + +/* Document + ========================================================================== */ + +html { + font-family: sans-serif; /* 1 */ + line-height: 1.15; /* 2 */ + -ms-text-size-adjust: 100%; /* 3 */ + -webkit-text-size-adjust: 100%; /* 3 */ +} + +/* Sections + ========================================================================== */ + +/** + * Remove the margin in all browsers (opinionated). + */ + +body { + margin: 0; +} + +/** + * Add the correct display in IE 9-. + */ + +article, +aside, +footer, +header, +nav, +section { + display: block; +} + +/** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/* Grouping content + ========================================================================== */ + +/** + * Add the correct display in IE 9-. + * 1. Add the correct display in IE. + */ + +figcaption, +figure, +main { /* 1 */ + display: block; +} + +/** + * Add the correct margin in IE 8. + */ + +figure { + margin: 1em 40px; +} + +/** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/* Text-level semantics + ========================================================================== */ + +/** + * 1. Remove the gray background on active links in IE 10. + * 2. Remove gaps in links underline in iOS 8+ and Safari 8+. + */ + +a { + background-color: transparent; /* 1 */ + -webkit-text-decoration-skip: objects; /* 2 */ +} + +/** + * Remove the outline on focused links when they are also active or hovered + * in all browsers (opinionated). + */ + +a:active, +a:hover { + outline-width: 0; +} + +/** + * 1. Remove the bottom border in Firefox 39-. + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ +} + +/** + * Prevent the duplicate application of `bolder` by the next rule in Safari 6. + */ + +b, +strong { + font-weight: inherit; +} + +/** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + +b, +strong { + font-weight: bolder; +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** + * Add the correct font style in Android 4.3-. + */ + +dfn { + font-style: italic; +} + +/** + * Add the correct background and color in IE 9-. + */ + +mark { + background-color: #ff0; + color: #000; +} + +/** + * Add the correct font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Add the correct display in IE 9-. + */ + +audio, +video { + display: inline-block; +} + +/** + * Add the correct display in iOS 4-7. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/** + * Remove the border on images inside links in IE 10-. + */ + +img { + border-style: none; +} + +/** + * Hide the overflow in IE. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* Forms + ========================================================================== */ + +/** + * 1. Change the font styles in all browsers (opinionated). + * 2. Remove the margin in Firefox and Safari. + */ + +button, +input, +optgroup, +select, +textarea { + font-family: sans-serif; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + +button, +input { /* 1 */ + overflow: visible; +} + +/** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + +button, +select { /* 1 */ + text-transform: none; +} + +/** + * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video` + * controls in Android 4. + * 2. Correct the inability to style clickable types in iOS and Safari. + */ + +button, +html [type="button"], /* 1 */ +[type="reset"], +[type="submit"] { + -webkit-appearance: button; /* 2 */ +} + +/** + * Remove the inner border and padding in Firefox. + */ + +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** + * Restore the focus styles unset by the previous rule. + */ + +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** + * Change the border, margin, and padding in all browsers (opinionated). + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ +} + +/** + * 1. Add the correct display in IE 9-. + * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + +progress { + display: inline-block; /* 1 */ + vertical-align: baseline; /* 2 */ +} + +/** + * Remove the default vertical scrollbar in IE. + */ + +textarea { + overflow: auto; +} + +/** + * 1. Add the correct box sizing in IE 10-. + * 2. Remove the padding in IE 10-. + */ + +[type="checkbox"], +[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + +[type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** + * Remove the inner padding and cancel buttons in Chrome and Safari on macOS. + */ + +[type="search"]::-webkit-search-cancel-button, +[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* Interactive + ========================================================================== */ + +/* + * Add the correct display in IE 9-. + * 1. Add the correct display in Edge, IE, and Firefox. + */ + +details, /* 1 */ +menu { + display: block; +} + +/* + * Add the correct display in all browsers. + */ + +summary { + display: list-item; +} + +/* Scripting + ========================================================================== */ + +/** + * Add the correct display in IE 9-. + */ + +canvas { + display: inline-block; +} + +/** + * Add the correct display in IE. + */ + +template { + display: none; +} + +/* Hidden + ========================================================================== */ + +/** + * Add the correct display in IE 10-. + */ + +[hidden] { + display: none; +} diff --git a/_static/css/space-sakura.css b/_static/css/space-sakura.css new file mode 100644 index 0000000..9c24ad6 --- /dev/null +++ b/_static/css/space-sakura.css @@ -0,0 +1,207 @@ +/* This stylesheet was modified from + Sakura.css v1.3.1 + * ================ + * Minimal css theme. + * Project: https://github.com/oxalorg/sakura/ + */ + + /* Color pallet +Original sakura-dark theme: + white: ffffff + light gray: e6e6e6 + medium-light gray: c9c9c9 + medium-dark gray: 4a4a4a + dark gray: 222222 + +Deep-space theme from: https://vimcolorschemes.com/rafi/awesome-vim-colorschemes + deep blue-gray: 1b202a (background) formerly 222222 + light blue-gray: 323c4d (contrasting background) formerly 4a4a4a + orangey: dfa276 (grabby text - links) formerly ffffff + light purpley: 8d70bc (visited) formerly e6e6e6 + c9c9c9 is still used in places + +Unused from theme: + light blue: 5e89bf (mildly grabby text) + redish pink: a65a76 (alternate grabby text) + light gray: 98a5ba (base text?) +*/ + +/* Body */ +html { + font-size: 62.5%; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; } + +body { + font-size: 1.8rem; + line-height: 1.5; + max-width: 40em; + margin: auto; + color: #c9c9c9; + background-color: #1b202a; + padding: 13px; } + +@media (max-width: 684px) { + body { + font-size: 1.53rem; } } + +@media (max-width: 382px) { + body { + font-size: 1.35rem; } } + +h1, h2, h3, h4, h5, h6 { + line-height: 1.1; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-weight: 700; + margin-top: 3rem; + margin-bottom: 1.5rem; + overflow-wrap: break-word; + word-wrap: break-word; + -ms-word-break: break-all; + word-break: break-word; } + +h1 { + font-size: 2.35em; } + +h2 { + font-size: 2.00em; } + +h3 { + font-size: 1.75em; } + +h4 { + font-size: 1.5em; } + +h5 { + font-size: 1.25em; } + +h6 { + font-size: 1em; } + +p { + margin-top: 0px; + margin-bottom: 1.5rem; } + +small, sub, sup { + font-size: 75%; } + +hr { + border-color: #dfa276; } + +a { + text-decoration: none; + color: #dfa276; } + a:hover { + color: #c9c9c9; + border-bottom: 2px solid #c9c9c9; } + a:visited { + color: #8d70bc; } + +ul { + padding-left: 1.4em; + margin-top: 0px; + margin-bottom: 1.5rem; } + +li { + margin-bottom: 0.2em; } + +blockquote { + margin-left: 0px; + margin-right: 0px; + padding-left: 1em; + padding-top: 0.8em; + padding-bottom: 0.8em; + padding-right: 0.8em; + border-left: 5px solid #dfa276; + margin-bottom: 1.5rem; + background-color: #323c4d; } + +blockquote p { + margin-bottom: 0; } + +img { + height: auto; + max-width: 100%; + margin-top: 0px; + margin-bottom: 2.5rem; } + +/* Pre and Code */ +pre { + background-color: #323c4d; + display: block; + padding: 1em; + overflow-x: auto; + margin-top: 0px; + margin-bottom: 2.5rem; } + +code { + font-size: 0.9em; + padding: 0 0.5em; + background-color: #323c4d; + white-space: pre-wrap; } + +pre > code { + padding: 0; + background-color: transparent; + white-space: pre; } + +/* Tables */ +table { + text-align: justify; + width: 100%; + border-collapse: collapse; } + +td, th { + padding: 0.5em; + border-bottom: 1px solid #323c4d; } + +/* Buttons, forms and input */ +input, textarea { + border: 1px solid #c9c9c9; } + input:focus, textarea:focus { + border: 1px solid #dfa276; } + +textarea { + width: 100%; } + +.button, button, input[type="submit"], input[type="reset"], input[type="button"] { + display: inline-block; + padding: 5px 10px; + text-align: center; + text-decoration: none; + white-space: nowrap; + background-color: #dfa276; + color: #1b202a; + border-radius: 1px; + border: 1px solid #dfa276; + cursor: pointer; + box-sizing: border-box; } + .button[disabled], button[disabled], input[type="submit"][disabled], input[type="reset"][disabled], input[type="button"][disabled] { + cursor: default; + opacity: .5; } + .button:focus:enabled, .button:hover:enabled, button:focus:enabled, button:hover:enabled, input[type="submit"]:focus:enabled, input[type="submit"]:hover:enabled, input[type="reset"]:focus:enabled, input[type="reset"]:hover:enabled, input[type="button"]:focus:enabled, input[type="button"]:hover:enabled { + background-color: #c9c9c9; + border-color: #c9c9c9; + color: #1b202a; + outline: 0; } + +textarea, select, input { + color: #c9c9c9; + padding: 6px 10px; + /* The 6px vertically centers text on FF, ignored by Webkit */ + margin-bottom: 10px; + background-color: #323c4d; + border: 1px solid #323c4d; + border-radius: 4px; + box-shadow: none; + box-sizing: border-box; } + textarea:focus, select:focus, input:focus { + border: 1px solid #dfa276; + outline: 0; } + +input[type="checkbox"]:focus { + outline: 1px dotted #dfa276; } + +label, legend, fieldset { + display: block; + margin-bottom: .5rem; + font-weight: 600; } diff --git a/_static/demo.html b/_static/demo.html new file mode 100644 index 0000000..01be547 --- /dev/null +++ b/_static/demo.html @@ -0,0 +1,209 @@ + + + + + sakura demo + + + + + +
+

Space Sakura Demo

+

This is an anchor tag/hyper link: sakura - Github Repository

+

Paragraphs look like this. Font size along with line height and maximum width are optimized for reading.

+ +

Italic, bold, and monospace. Itemized lists look like:

+ + +

Here's a block quote:

+
+

Man surprised me most about humanity. Because he sacrifices his health in order to make money. Then he sacrifices money to recuperate his health. And then he is so anxious about the future that he does not enjoy the present; the result being that he does not live in the present or the future; he lives as if he is never going to die, and then dies having never really lived. -James J Lachard

+
+ +

An h2 header

+

Some code blocks

+
define foobar() {
+    print "Welcome to flavor country!";
+}
+
+
import time
+# Quick, count to ten!
+for i in range(10):
+    # (but not *too* quick)
+    time.sleep(0.5)
+    print i
+
+ +

An h3 header

+

A nested list:

+
    +
  1. +

    First, get these ingredients:

    +
      +
    • carrots
    • +
    • celery
    • +
    • lentils
    • +
    +
  2. +
  3. +

    Boil some water.

    +
  4. +
  5. +

    Dump everything in the pot and follow this algorithm:

    +
    find wooden spoon
    +uncover pot
    +stir
    +cover pot
    +balance wooden spoon precariously on pot handle
    +wait 10 minutes
    +goto first step (or shut off burner when done)
    +

    Do not bump wooden spoon or it will fall.

    +
  6. +
+ +

Header level 1

+

Header level 2

+

Header level 3

+

Header level 4

+
Header level 5
+
Header level 6
+ +

A horizontal line:

+
+ +

Here's a link to a website, to a local doc, and to a section heading in the current doc. Here's a footnote 1.

+

Tables can look like this:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Shoes, their sizes, and what they're made of +
sizematerialcolor
9leatherbrown
10hemp canvasnatural
11glasstransparent
+

Multi-line tables:

+ + + + + + + + + + + + + + + + + + + + + +
keywordtext
redSunsets, apples, and other red or reddish things.
greenLeaves, grass, frogs and other things it's not easy being.
+ +

A horizontal rule follows.

+
+

Images are responsive by default:

+
+ example image +

example image

+
+ +
+ +

Form Elements

+
+
+

Input fields

+

+

+

+

+

+

+

+

+

+
+

[Top]

+
+

Select menus

+

+
+

[Top]

+
+

Checkboxes

+
    +
  • +
  • +
  • +
+
+

[Top]

+
+

Textareas

+

+

+
+

[Top]

+
+
+

Action buttons

+

+

+
+

[Top]

+
+
+
+
+
    +
  1. Footnote text goes here.↩

  2. +
+
+
+ + diff --git a/_static/templates/base.html b/_static/templates/base.html new file mode 100644 index 0000000..f4ef05d --- /dev/null +++ b/_static/templates/base.html @@ -0,0 +1,40 @@ +$-- This is a comment; Use $$ for literal $ +$-- Details for writing this template can be found: https://pandoc.org/MANUAL.html#templates +$-- ${foo} or $foo$ is an interpolated variable +$-- variables come from YAML front matter (or command line) +$-- ${if(variable)} conditional text ${endif} +$-- ${for(foo)} do thing $foo$ ${endfor} +$-- ${template-name.html} includes another template +$-- You can use pipes to transform variables if needed + + + + + $title$ + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(description)$ + +$endif$ +$if(tags)$ + +$endif$ +$-- + + + +
+

$title$

+
+$body$ + + \ No newline at end of file diff --git a/build/note1 b/build/note1 new file mode 100644 index 0000000..47b4fc5 --- /dev/null +++ b/build/note1 @@ -0,0 +1,21 @@ + + + + + Note 1 + + + + + + + +
+

Note 1

+
+

This is a note that links to note2.

+ + \ No newline at end of file diff --git a/build/note2 b/build/note2 new file mode 100644 index 0000000..2cf570e --- /dev/null +++ b/build/note2 @@ -0,0 +1,21 @@ + + + + + Note 2 + + + + + + + +
+

Note 2

+
+

This is a note that links to note1.

+ + \ No newline at end of file diff --git a/experiments.md b/experiments.md new file mode 100644 index 0000000..3f38c10 --- /dev/null +++ b/experiments.md @@ -0,0 +1,88 @@ +# Experiments with Publishing My Markdown Notes + +## Summary + +* Turns out I don't need an app, I need a renderer. +* Pandoc can render Markdown well. And now, it supports wikilinks. I might be +able to have "internal" linking. +* Find | Pandoc can work with a weird lambda-function kind of approach. +* Make files also work pretty well. +* I like sakura.css as a starting point: https://github.com/oxalorg/sakura +for styling. + +## Find | Pandoc + +Single doc: + +``` bash +pandoc --from=markdown+wikilinks_title_before_pipe --to=html5 -o build/note2 src/note2.md +``` + +Note: Pandoc complains if the build directory doesn't already exist. + +I think this should work. It grabs all the files in the src directory. +For each file it finds, run `pandoc ... ` and output to build/note1 or +build/note2. +``` bash +find . -path './src/*' -exec pandoc --from=markdown+wikilinks_title_before_pipe --to=html5 -o build/$(basename -s .md {}) {} \ +``` + +Output +``` +pandoc: build/./src/note2.md: withFile: does not exist (No such file or directory) +pandoc: build/./src/note1.md: withFile: does not exist (No such file or directory) +``` + +To confirm that the basename shenanigans is doing what I want: +``` bash +find . -path './src/*' -exec basename -s .md {} \; +# Output: note2\nnote1 +``` + +Furthermore, without the output specified, it concatenates the input files and writes to stdout: +``` +find . -path './src/*' -exec pandoc --from=markdown+wikilinks_title_before_pipe --to=html5 {} \; +``` + +This seems to identify the culprit! Something about passing +the found files into a subshell. +``` bash +find . -path './src/*' -exec echo build/$(basename -s .md {}) \; +# Output build/./src/note2.md... +``` + +This does it! +``` bash +find . -path './src/*' -exec sh -c 'pandoc --from=markdown+wikilinks_title_before_pipe --to=html5 -o build/$(basename -s .md $1) $1' _ {} \; +``` + +This is a pattern that I didn't expect for shells, but it's used elsewhere. +It's like defining a lambda function and applying it in one step. Only we are +using a subshell to define the lambda function. Here's the source from +[Stack Overflow](https://stackoverflow.com/questions/13833824/how-to-run-a-subcommand-inside-find-exec). + +1. In a subshell, *define a function* that you want to run. +2. When you close the subshell, the rest of the exec function applies the function. + +There is no passing the `{}` into the subshell. The `{}` exists in the original +`-exec` shell. Instead, you're doing some kooky function definition. + +Note: We are using `$1` to align with the convention that `$0` is the name and +`$1` is the first argument. + +From the man page of bash (emphasis mine): + +>-c If the -c option is present, then commands are read from the first +non-option argument command_string. If there are arguments after the command_string, *the first argument is assigned to $0 and any remaining +arguments are assigned to the positional parameters*. The assignment to $0 sets +the name of the shell, which is used in warning and error messages. + +# Conclusion +After tidying it all up, this command builds my entire stack of HTML and the links work! + +``` bash +find ~/notes/rocketbowman/tiddlers/ -path '*.md' -exec sh -c 'pandoc --from=markdown+wikilinks_title_before_pipe --to=html5 -o ~/tmp/build/$(basename -s .md $1) $1' _ {} \; +``` + +## A better conclusion +Turns out that a Makefile is the way to go. Create a rule for a 1-1 conversion. Then add a `make all` command. \ No newline at end of file diff --git a/link-dependencies.py b/link-dependencies.py new file mode 100644 index 0000000..593bd8a --- /dev/null +++ b/link-dependencies.py @@ -0,0 +1,86 @@ +import subprocess +import re +from pathlib import Path + +# Motivating Question: Can I develop a dependency list for a file based on +# the wikilinks within? + + +def extract_substrings(input_string): + # Get substrings between [[ and ]] + pattern = r'\[\[(.*?)\]\]' + matches = re.findall(pattern, input_string) + return matches + +def process_strings(string_list): + # If we are taking everything up to the pipe, we don't need if/else. + return [s.split('|')[0] for s in string_list] + +def test_extract_substrings(): + assert extract_substrings("Here are some substrings: [[first]], [[second]]") == ["first", "second"] + +def test_process_strings(): + assert process_strings(["wikilink|title","WikiLinkOnly"]) == ["wikilink","WikiLinkOnly"] + +def test_integration(): + extracted = extract_substrings("Titled Wikilink: [[wikilink|title]]; untitled Wikilink: [[WikilinkOnly]]") + processed = process_strings(extracted) + assert processed == ["wikilink", "WikiLinkOnly"] + +def run_pandoc(input_file, output_file, format='html'): + """ + Runs the pandoc command to convert a file to a different format. + + Parameters: + - input_file (str): Path to the input file. + - output_file (str): Path to the output file. + - format (str): Desired output format. Default is 'pdf'. + """ + + # Construct the command + command = [ + 'pandoc', + input_file, + '-o', + output_file, + '-t', + format + ] + + try: + result = subprocess.run(command, check=True, text=True, capture_output=True) + + # Print stdout and stderr + print("stdout:", result.stdout) + print("stderr:", result.stderr) + + except subprocess.CalledProcessError as e: + print("Error occurred while running pandoc:") + print(e.stderr) + except FileNotFoundError: + print("The 'pandoc' command was not found. Please make sure it is installed and in your PATH.") + except Exception as e: + print(f"An unexpected error occurred: {e}") + +# Example usage + + +if __name__=="__main__": + #test_extract_substrings() + #test_process_strings() + #print("all tests passed") + + base_dir = Path("/home/kyle/notes/rocketbowman/tiddlers") + file = base_dir / "ElectricityAndMagnetism.md" + with open(file, "r") as f: + content=f.read() + raw = extract_substrings(content) + processed = process_strings(raw) + print(f"Raw strings: {raw}") + print(f"Processed strings: {processed}") + + # Run pandoc + + input_path = base_dir / (processed[1] + ".md") + output_path = f"/home/kyle/tmp/{processed[1]}" + run_pandoc(input_path, output_path) \ No newline at end of file diff --git a/src/note1.md b/src/note1.md new file mode 100644 index 0000000..9663da6 --- /dev/null +++ b/src/note1.md @@ -0,0 +1,6 @@ +--- +title: Note 1 +author: Kyle Bowman +--- + +This is a note that links to [[note2]]. \ No newline at end of file diff --git a/src/note2.md b/src/note2.md new file mode 100644 index 0000000..2851e55 --- /dev/null +++ b/src/note2.md @@ -0,0 +1,6 @@ +--- +title: Note 2 +author: Kyle Bowman +--- + +This is a note that links to [[note1]]. \ No newline at end of file -- 2.39.5