News articles are now placed in separate pages.

Also given each rst file its rightful extension.
This commit is contained in:
Dominik Picheta 2016-06-04 22:06:50 +01:00
commit 16381364c2
37 changed files with 2624 additions and 2504 deletions

View file

@ -217,8 +217,8 @@ proc parseIniFile(c: var TConfigData) =
of "ticker": c.ticker = v
of "documentation":
case normalize(k.key)
of "doc": addFiles(c.doc, "doc", ".txt", split(v, {';'}))
of "pdf": addFiles(c.pdf, "doc", ".txt", split(v, {';'}))
of "doc": addFiles(c.doc, "doc", ".rst", split(v, {';'}))
of "pdf": addFiles(c.pdf, "doc", ".rst", split(v, {';'}))
of "srcdoc": addFiles(c.srcdoc, "lib", ".nim", split(v, {';'}))
of "srcdoc2": addFiles(c.srcdoc2, "lib", ".nim", split(v, {';'}))
of "webdoc": addFiles(c.webdoc, "lib", ".nim", split(v, {';'}))
@ -406,9 +406,9 @@ proc generateRss(outputFilename: string, news: seq[TRssItem]) =
output.write("""</feed>""")
proc buildNewsRss(c: var TConfigData, destPath: string) =
# generates an xml feed from the web/news.txt file
# generates an xml feed from the web/news.rst file
let
srcFilename = "web" / "news.txt"
srcFilename = "web" / "news.rst"
destFilename = destPath / changeFileExt(splitFile(srcFilename).name, "xml")
generateRss(destFilename, parseNewsTitles(srcFilename))
@ -441,9 +441,38 @@ proc buildSponsors(c: var TConfigData, sponsorsFile: string, outputDir: string)
else:
quit("[Error] Cannot write file: " & outFile)
const
cmdRst2Html = "nim rst2html --compileonly $1 -o:web/$2.temp web/$2.rst"
proc buildPage(c: var TConfigData, file, rss: string, assetDir = "") =
exec(cmdRst2Html % [c.nimArgs, file])
var temp = "web" / changeFileExt(file, "temp")
var content: string
try:
content = readFile(temp)
except IOError:
quit("[Error] cannot open: " & temp)
var f: File
var outfile = "web/upload/$#.html" % file
if not existsDir(outfile.splitFile.dir):
createDir(outfile.splitFile.dir)
if open(f, outfile, fmWrite):
writeLine(f, generateHTMLPage(c, file, content, rss, assetDir))
close(f)
else:
quit("[Error] cannot write file: " & outfile)
removeFile(temp)
proc buildNews(c: var TConfigData, newsDir: string, outputDir: string) =
for kind, path in walkDir(newsDir):
let (dir, name, ext) = path.splitFile
if ext == ".rst":
buildPage(c, tailDir(dir) / name, "", "../")
else:
echo("Skipping file in news directory: ", path)
proc buildWebsite(c: var TConfigData) =
const
cmd = "nim rst2html --compileonly $1 -o:web/$2.temp web/$2.txt"
if c.ticker.len > 0:
try:
c.ticker = readFile("web" / c.ticker)
@ -453,26 +482,11 @@ proc buildWebsite(c: var TConfigData) =
var file = c.tabs[i].val
let rss = if file in ["news", "index"]: extractFilename(rssUrl) else: ""
if '.' in file: continue
exec(cmd % [c.nimArgs, file])
var temp = "web" / changeFileExt(file, "temp")
var content: string
try:
content = readFile(temp)
except IOError:
quit("[Error] cannot open: " & temp)
var f: File
var outfile = "web/upload/$#.html" % file
if not existsDir("web/upload"):
createDir("web/upload")
if open(f, outfile, fmWrite):
writeLine(f, generateHTMLPage(c, file, content, rss))
close(f)
else:
quit("[Error] cannot write file: " & outfile)
removeFile(temp)
buildPage(c, file, rss)
copyDir("web/assets", "web/upload/assets")
buildNewsRss(c, "web/upload")
buildSponsors(c, sponsors, "web/upload")
buildNews(c, "web/news", "web/upload/news")
proc main(c: var TConfigData) =
buildWebsite(c)

View file

@ -1,13 +1,14 @@
#? stdtmpl | standard
#proc generateHTMLPage(c: var TConfigData, currentTab, content, rss: string): string =
#proc generateHTMLPage(c: var TConfigData, currentTab, content, rss,
# rootDir = ""): string =
# result = ""
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>${currentTab} - $c.projectTitle</title>
<link rel="stylesheet" type="text/css" href="assets/style.css?t=2221" />
<link rel="shortcut icon" href="assets/images/favicon.ico">
<link rel="stylesheet" type="text/css" href="${rootDir}assets/style.css?t=2221" />
<link rel="shortcut icon" href="${rootDir}assets/images/favicon.ico">
#if len(rss) > 0:
<link href="$rss" title="Recent changes" type="application/atom+xml" rel="alternate">
#end if
@ -16,7 +17,7 @@
<div id="bountysource">
<a href="https://salt.bountysource.com/teams/nim">
<div class="page-layout" style="padding: 2pt 2pt 2pt 30pt">
<img src="assets/bountysource/bountysource.png" style="width: 20px; float: left;">
<img src="${rootDir}assets/bountysource/bountysource.png" style="width: 20px; float: left;">
<span style="margin-left: 10pt; float: left; margin-top: 2pt;">Fund Nim and help us develop it further!</span>
<img src="https://api.bountysource.com/badge/team?team_id=19072&style=raised" style="margin-top: 2pt; margin-left: 10pt"/>
</div>
@ -26,7 +27,7 @@
<header id="head">
<div class="page-layout tall">
<div id="head-logo"></div>
<a id="head-logo-link" href="index.html"></a>
<a id="head-logo-link" href="${rootDir}index.html"></a>
<nav id="head-links">
#for i in 0.. c.tabs.len-1:
# let t = c.tabs[i].val
@ -40,7 +41,7 @@
# if t.contains('.'):
href="${t}" title = "$c.projectName - $name">$name</a>
# else:
href="${t}.html" title = "$c.projectName - $name">$name</a>
href="${rootDir}${t}.html" title = "$c.projectName - $name">$name</a>
# end if
# end if
#end for
@ -61,12 +62,12 @@
<!-- slides -->
<div id="slide0" class="active niaslide">
<a href="sponsors.html">
<img src="assets/bountysource/meet_sponsors.png" alt="Meet our BountySource sponsors!"/>
<img src="${rootDir}assets/bountysource/meet_sponsors.png" alt="Meet our BountySource sponsors!"/>
</a>
</div>
<div id="slide1" class="niaslide">
<a href="news.html#Z2016-01-27-nim-in-action-is-now-available">
<img src="assets/niminaction/banner.jpg" alt="New in Manning Early Access Program: Nim in Action!"/>
<img src="${rootDir}assets/niminaction/banner.jpg" alt="New in Manning Early Access Program: Nim in Action!"/>
</a>
</div>
<div id="slide2" class="codeslide2">
@ -156,7 +157,7 @@ runForever()
# if len(c.ticker) > 0:
<h3 class="blue">Latest News</h3>
<div id="sidebar-news">
$c.ticker
${c.ticker % rootDir}
</div>
# end if
</aside>
@ -200,7 +201,7 @@ runForever()
</footer>
# if currentTab == "index":
<script src="assets/index.js"></script>
<script src="${rootDir}assets/index.js"></script>
# end if
# if c.gaId != nil:
<script>