-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c925516
commit 1f49f60
Showing
11 changed files
with
365 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# # | ||
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ # | ||
# ┃ ┃ # | ||
# ┃ MarkedDown/News ┃ # | ||
# ┃ Action Settings ┃ # | ||
# ┃ ┃ # | ||
# ┃ 🗞 News sections generated from your input. ┃ # | ||
# ┃ ┃ # | ||
# ┃ https://github.com/MarkedDown/News ┃ # | ||
# ┃ ┃ # | ||
# ┃ ┃ # | ||
# ┃ Configuration ┃ # | ||
# ┠────────────────────────────────────────────────────────────────────────┨ # | ||
# ┃ ┃ # | ||
# ┃ A configuration describes from where data ┃ # | ||
# ┃ should be loaded and where to inject it. ┃ # | ||
# ┃ ┃ # | ||
# ┃ ┃ # | ||
# ┃ Example ┃ # | ||
# ┠────────────────────────────────────────────────────────────────────────┨ # | ||
# ┃ ┃ # | ||
# ┃ - Inject : Example/README.md ┃ # | ||
# ┃ Input : Example/News.yaml ┃ # | ||
# ┃ ┃ # | ||
# ┃ ┃ # | ||
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ # | ||
# # | ||
|
||
|
||
- Inject : Example/README.md | ||
Input : Example/News.yaml | ||
|
||
test : testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
# | ||
# News Articles | ||
# ============= | ||
# | ||
# Structure: | ||
# ---------- | ||
# | ||
# - title : <Title> | ||
# | ||
# lines : | | ||
# <Line> | ||
# <Line> | ||
# | ||
# links : | ||
# <Link Name> : <Url> | ||
# | ||
# Warning: | ||
# -------- | ||
# | ||
# Lines shouldn't be longer than 50 characters. | ||
# | ||
##########################################################| Stop Here | ||
# | ||
|
||
|
||
- title : 🔬 Testing | ||
|
||
lines : | | ||
This is a test message! | ||
- title : 🔬 Testing | ||
|
||
lines : | | ||
This is a test message! | ||
- title : 🔬 Testing | ||
|
||
lines : | | ||
This is a test message! | ||
- title : 🔬 Testing | ||
|
||
lines : | | ||
This is a test message! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
<!---------------------------------- 🗞 News ----------------------------------> | ||
|
||
<pre align = center> | ||
|
||
<kbd align = left> <br> <b>🔬 Testing</b><br> <br> This is a test message!<br> <br> </kbd> <kbd align = left> <br> <b>🔬 Testing</b><br> <br> This is a test message!<br> <br> </kbd><br><br><kbd align = left> <br> <b>🔬 Testing</b><br> <br> This is a test message!<br> <br> </kbd> <kbd align = left> <br> <b>🔬 Testing</b><br> <br> This is a test message!<br> <br> </kbd> | ||
|
||
</pre> | ||
|
||
<!---------------------------------- 🗞 News ----------------------------------> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import { insertNews } from './Readme.ts' | ||
|
||
import configs from './Config.ts' | ||
|
||
|
||
const | ||
{ writeTextFile , readTextFile } = Deno , | ||
{ log } = console ; | ||
|
||
|
||
log(`🗞 Inserting updated News`); | ||
|
||
|
||
for ( const config of configs ){ | ||
|
||
log(` | ||
Building Config | ||
Inject : ${ config.Inject } | ||
Input : ${ config.Input } | ||
`) | ||
|
||
const readme = await readTextFile(config.Inject); | ||
|
||
const updated = await insertNews(readme,config); | ||
|
||
await writeTextFile(config.Inject,updated); | ||
|
||
} | ||
|
||
|
||
log(`🗞 Finished news insertion`); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
import { parse as parseYAML } from 'YAML' | ||
import { setFailed } from 'Actions' | ||
import { parse } from 'Flags' | ||
import { join } from 'Path' | ||
|
||
|
||
export interface Config { | ||
Inject : string | ||
Input : string | ||
} | ||
|
||
const { readTextFile , args , env } = Deno; | ||
|
||
|
||
const repository = env | ||
.get('GITHUB_WORKSPACE') as string; | ||
|
||
|
||
const flags = parse(args); | ||
|
||
const config = join(repository,flags.config); | ||
|
||
|
||
|
||
const yaml = await readTextFile(config) | ||
.catch(fail) as string | ||
|
||
|
||
const configs = <Config []> | ||
parseYAML(yaml) | ||
|
||
|
||
export default configs | ||
|
||
|
||
|
||
function fail (){ | ||
|
||
setFailed(` | ||
The given config path cannot be found! | ||
Path : \`${ config }\` | ||
`) | ||
|
||
Deno.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
import { loadNews , News } from './News.ts' | ||
import { Config } from './Config.ts' | ||
import { chunk } from 'Chunk' | ||
|
||
|
||
const { log } = console; | ||
|
||
|
||
const Fill = '-'.repeat(34); | ||
|
||
const Mark = `<!${ Fill } 🗞 News ${ Fill }>`; | ||
|
||
|
||
const Space = ' '; | ||
|
||
|
||
const indent = ( line : string ) => | ||
`${ Space.repeat(3) }${ line }` | ||
|
||
const trim = ( line : string ) => | ||
line.trim(); | ||
|
||
|
||
const link = /(\[[\S\s]+?\])/g | ||
|
||
|
||
|
||
|
||
function toPanel ( news : News ){ | ||
|
||
const { links = {} } = news; | ||
|
||
const insertLinks = ( line : string ) => | ||
line.replaceAll(link,( text ) => { | ||
|
||
const name = text | ||
.slice(1,-1); | ||
|
||
const url = links[name] ?? '#'; | ||
|
||
return `<a href = '${ url }'>${ name }</a>` | ||
}) | ||
|
||
|
||
const { title , lines } = news; | ||
|
||
const rows = lines | ||
.split('\n') | ||
.map(trim); | ||
|
||
rows.unshift(`<b>${ title }</b>`,''); | ||
|
||
const text = rows | ||
.map(indent) | ||
.map(insertLinks) | ||
.join('<br>'); | ||
|
||
return [ | ||
`<kbd align = left>${ Space }<br>` , | ||
text , | ||
`<br>${ Space.repeat(80) }</kbd>` | ||
].join('') | ||
} | ||
|
||
|
||
export async function compileNews ( config : Config ){ | ||
|
||
const articles = await loadNews(config); | ||
|
||
log(`🗞 Found ${ articles.length } news articles`) | ||
|
||
const panels = articles | ||
.map(toPanel); | ||
|
||
const news = chunk(panels,2) | ||
.map(( pair ) => pair.join(Space.repeat(5))) | ||
.join('<br><br>'); | ||
|
||
const items = [ | ||
Mark , | ||
'<pre align = center>' , | ||
news , | ||
'</pre>' , | ||
Mark | ||
] | ||
|
||
return items | ||
.join('\n \n') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import { Config } from './Config.ts' | ||
import { parse } from 'YAML' | ||
|
||
const { readTextFile } = Deno; | ||
|
||
|
||
export interface News { | ||
|
||
title : News | ||
|
||
lines : string | ||
|
||
links ?: { | ||
[ alias : string ] : string | ||
} | ||
} | ||
|
||
|
||
export async function loadNews ( config : Config ){ | ||
|
||
const yaml = await readTextFile(config.Input); | ||
|
||
return <News[]> | ||
parse(yaml) ?? [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
import { compileNews } from './Content.ts' | ||
import { Config } from './Config.ts' | ||
|
||
const | ||
content = `[\\s\\S]+?` , | ||
marker = `<!-{2,} *🗞 News *-{2,}>` , | ||
pattern = `${ marker }(${ content })${ marker }` ; | ||
|
||
const outdated = | ||
new RegExp(pattern,'im'); | ||
|
||
|
||
export async function insertNews ( readme : string , config : Config ){ | ||
|
||
const news = await compileNews(config); | ||
|
||
return readme | ||
.replace(outdated,news); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.