From 652743fd9da848eec2f4936e0d5dc176c35ccaf1 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 13:25:57 +0300 Subject: [PATCH 1/7] use locale date config option --- build.ts | 5 +++-- config.ts | 6 ++++-- views/base.eta | 16 +++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/build.ts b/build.ts index 430cd92..2df66db 100644 --- a/build.ts +++ b/build.ts @@ -108,8 +108,9 @@ export async function buildPage( pagesByTag: taggedPages, childTags: opts.childTags, site: opts.userConfig.site, - author: opts.userConfig.author, - navigation: opts.userConfig.navigation, + author: opts.userConfig?.author, + locale: opts.userConfig?.locale, + navigation: opts.userConfig?.navigation, style: opts.style, includeRefresh: opts.includeRefresh, }); diff --git a/config.ts b/config.ts index 14548b1..e482d16 100644 --- a/config.ts +++ b/config.ts @@ -10,7 +10,10 @@ export interface UserConfig { rootCrumb: string; }; author: { name: string; email: string; url: string }; - navigation: Record; + navigation?: Record; + locale?: { + date?: string; + }; } export interface BuildConfig { @@ -35,7 +38,6 @@ const defaultUserConfig: UserConfig = { url: "https://example.com/", rootCrumb: "index", }, - navigation: {}, author: { name: "Your Name Here", email: "youremailaddress@example.com", diff --git a/views/base.eta b/views/base.eta index d61fcf9..41b421b 100644 --- a/views/base.eta +++ b/views/base.eta @@ -3,12 +3,13 @@ const { crumbs, childPages, childTags, backlinkPages, pagesByTag, toc, indexLayout, page, site, includeRefresh, style, navigation, - author + author, locale } = it; const { title, description, date, tags, headings, html } = page; const filteredHeadings = headings && headings.filter(h => h.level >= 2 && h.level <= 5) -const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; +const datePageOpts = { year: 'numeric', month: 'short', day: 'numeric' }; +const dateIndexOpts = { year: 'numeric', month: 'numeric', day: 'numeric' }; %> @@ -89,7 +90,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <% if (date || (tags && tags.length > 0)) { %>
<% if (date) { %> - + <% } %> <% if (tags && tags.length > 0 ) { %> <% if (date && (tags && tags.length > 0)) { %> @@ -147,7 +148,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' };

<%~ title %>

<% if (date || (tags && tags.length > 0)) { %>
- + <% if (tags && tags.length > 0 ) { %> <% if (date && (tags && tags.length > 0)) { %> · @@ -193,7 +194,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <% if (isIndex) { %>/ ..<% } %> <% if (date) { %> - + <% } %> <% }) %> @@ -220,6 +221,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <%= title %> <% if (date) { %> + <% } %> <% }) %> @@ -237,7 +239,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <%= title %> <% if (date) { %> - + <% } %> <% }) %> @@ -251,7 +253,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; Made with Ter. Feed - + From b8d8d9c10a42d49c2d013ee534486390b3191d6a Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 13:25:57 +0300 Subject: [PATCH 2/7] use locale date config option --- build.ts | 5 +++-- config.ts | 6 ++++-- views/base.eta | 16 +++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/build.ts b/build.ts index 430cd92..2df66db 100644 --- a/build.ts +++ b/build.ts @@ -108,8 +108,9 @@ export async function buildPage( pagesByTag: taggedPages, childTags: opts.childTags, site: opts.userConfig.site, - author: opts.userConfig.author, - navigation: opts.userConfig.navigation, + author: opts.userConfig?.author, + locale: opts.userConfig?.locale, + navigation: opts.userConfig?.navigation, style: opts.style, includeRefresh: opts.includeRefresh, }); diff --git a/config.ts b/config.ts index 14548b1..e482d16 100644 --- a/config.ts +++ b/config.ts @@ -10,7 +10,10 @@ export interface UserConfig { rootCrumb: string; }; author: { name: string; email: string; url: string }; - navigation: Record; + navigation?: Record; + locale?: { + date?: string; + }; } export interface BuildConfig { @@ -35,7 +38,6 @@ const defaultUserConfig: UserConfig = { url: "https://example.com/", rootCrumb: "index", }, - navigation: {}, author: { name: "Your Name Here", email: "youremailaddress@example.com", diff --git a/views/base.eta b/views/base.eta index d61fcf9..41b421b 100644 --- a/views/base.eta +++ b/views/base.eta @@ -3,12 +3,13 @@ const { crumbs, childPages, childTags, backlinkPages, pagesByTag, toc, indexLayout, page, site, includeRefresh, style, navigation, - author + author, locale } = it; const { title, description, date, tags, headings, html } = page; const filteredHeadings = headings && headings.filter(h => h.level >= 2 && h.level <= 5) -const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; +const datePageOpts = { year: 'numeric', month: 'short', day: 'numeric' }; +const dateIndexOpts = { year: 'numeric', month: 'numeric', day: 'numeric' }; %> @@ -89,7 +90,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <% if (date || (tags && tags.length > 0)) { %>
<% if (date) { %> - + <% } %> <% if (tags && tags.length > 0 ) { %> <% if (date && (tags && tags.length > 0)) { %> @@ -147,7 +148,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' };

<%~ title %>

<% if (date || (tags && tags.length > 0)) { %>
- + <% if (tags && tags.length > 0 ) { %> <% if (date && (tags && tags.length > 0)) { %> · @@ -193,7 +194,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <% if (isIndex) { %>/ ..<% } %> <% if (date) { %> - + <% } %> <% }) %> @@ -220,6 +221,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <%= title %> <% if (date) { %> + <% } %> <% }) %> @@ -237,7 +239,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; <%= title %> <% if (date) { %> - + <% } %> <% }) %> @@ -251,7 +253,7 @@ const dateOpts = { year: 'numeric', month: 'short', day: 'numeric' }; Made with Ter. Feed - + From 7c88597968d136e86812dedf4c86a653ab4d8d40 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 21:22:03 +0300 Subject: [PATCH 3/7] update config --- .ter/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ter/config.json b/.ter/config.json index 78dd05a..be002eb 100644 --- a/.ter/config.json +++ b/.ter/config.json @@ -6,7 +6,7 @@ }, "navigation": { "Usage": "/usage", - "Source code": "https://github.com/kkga/ter" + "Source": "https://github.com/kkga/ter" }, "author": { "name": "Gadzhi Kharkharov", From a56e3f41067b39ff83a7f4fe7ff2f850b4f9cd32 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 21:22:20 +0300 Subject: [PATCH 4/7] docs: add locale date example --- docs/usage.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/usage.md b/docs/usage.md index 786a37d..a6eb9fd 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -105,10 +105,15 @@ doesn't exist, an example configuration file is created before building. "navigation": { "about": "/about", "contact": "/contact" + }, + "locale": { + "date": "en-US" } } ``` +The `navigation` and `locale` keys are optional. + --- ## Index pages From 4782098c5841e4d2054a4898bb6bd2a09250c558 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 21:46:19 +0300 Subject: [PATCH 5/7] docs: document configuration options --- docs/usage.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index a6eb9fd..b022801 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -84,10 +84,27 @@ deno run -A --unstable https://deno.land/x/ter/main.ts --serve ## Configuration -Before building, Ter checks for configuration file at `.ter/config.json`. If it -doesn't exist, an example configuration file is created before building. +Configuration options can be specified in `.ter/config.json` from the root +directory or in any `json` file specified with `--config` flag when running Ter. -##### Example +If the file does not exist, an example configuration file is created before +building. + +### Options + +| Key | Description | +| ------------------ | -------------------------------------------------------------- | +| `site.title` | Title of your site. | +| `site.description` | Description of your site. | +| `site.url` | Published URL address of your site. | +| `site.rootCrumb` | Label used for root crumb label (default: "index"). | +| `author.name` | Your name. | +| `author.email` | Your email. | +| `author.url` | Your home page. | +| `navigation` | Optional. Object of navigation items in form of `label: path`. | +| `locale.date` | Optional. Locale used for formatting dates. | + +### Example ```json { @@ -112,8 +129,6 @@ doesn't exist, an example configuration file is created before building. } ``` -The `navigation` and `locale` keys are optional. - --- ## Index pages @@ -218,12 +233,9 @@ after building a site. Here's an example output: ``` [...] - Dead links: /overview -> /non-existent-page-name /overview -> /some-dead-link - -[...] ``` --- @@ -243,19 +255,19 @@ If using non-default input and output folders, update the build command and output directory accordingly. -##### Build command +#### Build command ``` deno run -A --unstable https://deno.land/x/ter/main.ts ``` -##### Output directory +#### Output directory ``` _site ``` -##### Install command +#### Install command ``` curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL=/usr/local sh From c5e22e28c46e33d568614f9ad036d3bf89e4821a Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 21:48:52 +0300 Subject: [PATCH 6/7] docs: fix achors --- docs/usage.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index b022801..bd33528 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -153,8 +153,8 @@ content. Items in the index are sorted in the following order: -1. files with `pinned: true` in the [frontmatter](#frontmatter) are listed at - the top and get an ★ symbol; +1. files with `pinned: true` in the [frontmatter](#markdown-frontmatter) are + listed at the top and get an ★ symbol; 2. directories (child index pages); 3. rest of markdown files, sorted by [date](#dates). @@ -213,7 +213,7 @@ skipped during site generation. ### Draft pages In addition, any markdown file with `draft: true` in the -[frontmatter](#frontmatter) will be ignored. +[frontmatter](#markdown-frontmatter) will be ignored. ### Rendering draft pages From 12ae84a1b03ae73e2c85d7c750bc5c39eaee5d33 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 21:52:25 +0300 Subject: [PATCH 7/7] server: show path relative to cwd --- serve.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/serve.ts b/serve.ts index 8a3f019..0df85fd 100644 --- a/serve.ts +++ b/serve.ts @@ -19,9 +19,16 @@ const sockets: Set = new Set(); let servePath: string; async function watch(opts: WatchOpts) { - const watcher = Deno.watchFs(opts.config.inputPath); + const paths = [opts.config.inputPath, join(Deno.cwd(), ".ter")]; + const watcher = Deno.watchFs(paths); let timer = 0; + const isInOutputDir = (path: string): boolean => + relative(opts.config.outputPath, path).startsWith(".."); + + // const isInConfigDir = (path: string): boolean => + // relative(join(Deno.cwd(), ".ter"), path).startsWith("..") === false; + eventLoop: for await (const event of watcher) { if (["any", "access"].includes(event.kind)) { @@ -30,15 +37,14 @@ async function watch(opts: WatchOpts) { for (const eventPath of event.paths) { if ( - eventPath.match(RE_HIDDEN_OR_UNDERSCORED) || - !relative(opts.config.outputPath, eventPath).startsWith("..") + eventPath.match(RE_HIDDEN_OR_UNDERSCORED) || !isInOutputDir(eventPath) ) { continue eventLoop; } } console.log( - `>>> ${event.kind}: ${relative(opts.config.inputPath, event.paths[0])}`, + `>>> ${event.kind}: ${relative(Deno.cwd(), event.paths[0])}`, ); await opts.runner({ config: opts.config,