Get rid of source which is easily deducible from the articles key and articlesPath
This commit is contained in:
parent
ad5c8a0130
commit
85b71262be
9 changed files with 37 additions and 36 deletions
|
@ -37,15 +37,15 @@ function DomRenderer(modules) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function article(url, markdown, limit) {
|
function article(key, markdown, limit) {
|
||||||
var headerEnd = markdown.search(/\n\n/);
|
var url = ["", blog.path.articlesPath, key + (limit != undefined ? '.html' : '.md')].join('/');
|
||||||
var header = getDiv(markdown.slice(0, headerEnd));
|
var lines = markdown.split(/\n/).slice(blog.articles[key].bodyOffset);
|
||||||
var lines = markdown.slice(headerEnd+2).split(/\n/);
|
|
||||||
var div = getDiv(lines.slice(0, limit).join('\n'));
|
var div = getDiv(lines.slice(0, limit).join('\n'));
|
||||||
var title = header.getElementsByTagName('h1')[0];
|
return modules.dom.make('article', {}, [
|
||||||
return title == undefined ? null : modules.dom.make('article', {}, [
|
|
||||||
modules.dom.make('header', {}, [
|
modules.dom.make('header', {}, [
|
||||||
modules.dom.make('a', {class: (limit != undefined ? 'navigation' : []), href: url}, [title])
|
modules.dom.make('a', {class: (limit != undefined ? 'navigation' : []), href: url}, [
|
||||||
|
modules.dom.make('h1', {innerText: blog.articles[key].title})
|
||||||
|
])
|
||||||
]),
|
]),
|
||||||
div
|
div
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
function Navigation(modules) {
|
function Navigation(modules) {
|
||||||
var articles = modules.cache.make(function(url) {
|
var articles = modules.cache.make(function(key) {
|
||||||
|
var url = ["", blog.path.articlesPath, key + '.md'].join('/');
|
||||||
return modules.async.bind(
|
return modules.async.bind(
|
||||||
modules.async.http({method: 'GET', url: url}),
|
modules.async.http({method: 'GET', url: url}),
|
||||||
function(queryResult) {
|
function(queryResult) {
|
||||||
|
@ -42,30 +43,29 @@ function Navigation(modules) {
|
||||||
var path = url.split("/").slice(1);
|
var path = url.split("/").slice(1);
|
||||||
if(blog.tags[path[0]] != undefined) {
|
if(blog.tags[path[0]] != undefined) {
|
||||||
show(getArticlesList(path[0], path[1] == "all.html"));
|
show(getArticlesList(path[0], path[1] == "all.html"));
|
||||||
} else if(path[0].length > 0 && !path[0].match(/\.html$/)) {
|
} else if(path[0] == blog.path.articlesPath) {
|
||||||
show(getArticle(url.replace(/html$/, 'md')));
|
show(getArticle(path[1].replace(/\.html$/, '')));
|
||||||
} else {
|
} else {
|
||||||
show(getArticlesList(null, path[0] == "all.html"));
|
show(getArticlesList(null, path[0] == "all.html"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArticle(url) {
|
function getArticle(key) {
|
||||||
return modules.async.bind(
|
return modules.async.bind(
|
||||||
articles.get(url),
|
articles.get(key),
|
||||||
modules.async.map(
|
modules.async.map(
|
||||||
function(contents) {return [modules.domRenderer.article(url, contents)];}
|
function(contents) {return [modules.domRenderer.article(key, contents)];}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function preview(articleId) {
|
function preview(key) {
|
||||||
var source = blog.articles[articleId].source;
|
|
||||||
return modules.async.bind(
|
return modules.async.bind(
|
||||||
articles.get(source),
|
articles.get(key),
|
||||||
function(contents) {
|
function(contents) {
|
||||||
return modules.async.wrap(
|
return modules.async.wrap(
|
||||||
modules.domRenderer.article(
|
modules.domRenderer.article(
|
||||||
source.replace(/md$/, 'html'),
|
key,
|
||||||
contents,
|
contents,
|
||||||
blog.skin.previewLinesCount
|
blog.skin.previewLinesCount
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module Article (
|
module Article (
|
||||||
Article(..)
|
Article(..)
|
||||||
, at
|
, at
|
||||||
, key
|
, getKey
|
||||||
, preview
|
, preview
|
||||||
, titleP
|
, titleP
|
||||||
) where
|
) where
|
||||||
|
@ -27,7 +27,7 @@ import Text.ParserCombinators.Parsec (
|
||||||
type Metadata = Map String String
|
type Metadata = Map String String
|
||||||
|
|
||||||
data Article = Article {
|
data Article = Article {
|
||||||
urlPath :: FilePath
|
key :: String
|
||||||
, title :: String
|
, title :: String
|
||||||
, metadata :: Metadata
|
, metadata :: Metadata
|
||||||
, bodyOffset :: Int
|
, bodyOffset :: Int
|
||||||
|
@ -87,9 +87,9 @@ at filePath = do
|
||||||
fmap build . parse articleP filePath <$> readFile filePath
|
fmap build . parse articleP filePath <$> readFile filePath
|
||||||
where
|
where
|
||||||
makeArticle metaFilter (title, metadata, bodyOffset, body) = (
|
makeArticle metaFilter (title, metadata, bodyOffset, body) = (
|
||||||
key filePath
|
getKey filePath
|
||||||
, Article {
|
, Article {
|
||||||
urlPath = dropExtension filePath
|
key = getKey filePath
|
||||||
, title
|
, title
|
||||||
, metadata = metaFilter metadata
|
, metadata = metaFilter metadata
|
||||||
, bodyOffset
|
, bodyOffset
|
||||||
|
@ -97,8 +97,8 @@ at filePath = do
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
key :: FilePath -> String
|
getKey :: FilePath -> String
|
||||||
key = dropExtension . takeFileName
|
getKey = dropExtension . takeFileName
|
||||||
|
|
||||||
preview :: Int -> Article -> Article
|
preview :: Int -> Article -> Article
|
||||||
preview linesCount article = article {body = take linesCount $ body article}
|
preview linesCount article = article {body = take linesCount $ body article}
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Blog (
|
||||||
import Arguments (Arguments)
|
import Arguments (Arguments)
|
||||||
import qualified Arguments (name)
|
import qualified Arguments (name)
|
||||||
import Article (Article)
|
import Article (Article)
|
||||||
import qualified Article (at, key)
|
import qualified Article (at, getKey)
|
||||||
import Blog.Path (Path(..))
|
import Blog.Path (Path(..))
|
||||||
import qualified Blog.Path as Path (build)
|
import qualified Blog.Path as Path (build)
|
||||||
import Blog.Skin (Skin(..))
|
import Blog.Skin (Skin(..))
|
||||||
|
@ -57,7 +57,7 @@ tagged collection path = do
|
||||||
keys <- forM links $ \link -> do
|
keys <- forM links $ \link -> do
|
||||||
fileExists <- doesFileExist link
|
fileExists <- doesFileExist link
|
||||||
return $ if fileExists
|
return $ if fileExists
|
||||||
then let articleKey = Article.key link in
|
then let articleKey = Article.getKey link in
|
||||||
if Map.member articleKey collection then Set.singleton articleKey else Set.empty
|
if Map.member articleKey collection then Set.singleton articleKey else Set.empty
|
||||||
else Set.empty
|
else Set.empty
|
||||||
return (takeFileName path, foldl Set.union Set.empty keys)
|
return (takeFileName path, foldl Set.union Set.empty keys)
|
||||||
|
|
|
@ -24,7 +24,7 @@ data Skin = Skin {
|
||||||
findFavicon :: Arguments -> IO (Maybe FilePath)
|
findFavicon :: Arguments -> IO (Maybe FilePath)
|
||||||
findFavicon arguments =
|
findFavicon arguments =
|
||||||
case Arguments.favicon arguments of
|
case Arguments.favicon arguments of
|
||||||
Just path -> return $ Just path
|
Just path -> return . Just $ absolute path
|
||||||
_ -> fmap absolute . listToMaybe <$> filterM doesFileExist pathsToCheck
|
_ -> fmap absolute . listToMaybe <$> filterM doesFileExist pathsToCheck
|
||||||
where
|
where
|
||||||
directories = [".", "image", "images", "pictures", "skin", "static"]
|
directories = [".", "image", "images", "pictures", "skin", "static"]
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Dom (
|
||||||
import Article (Article(..))
|
import Article (Article(..))
|
||||||
import qualified Article (preview)
|
import qualified Article (preview)
|
||||||
import ArticlesList (ArticlesList(..), otherLink, otherUrl, pageTitle)
|
import ArticlesList (ArticlesList(..), otherLink, otherUrl, pageTitle)
|
||||||
import Blog (Blog(..), Skin(..))
|
import Blog (Blog(..), Path(..), Skin(..))
|
||||||
import qualified Blog (get)
|
import qualified Blog (get)
|
||||||
import Control.Monad.Reader (ReaderT)
|
import Control.Monad.Reader (ReaderT)
|
||||||
import qualified Data.Map as Map (keys)
|
import qualified Data.Map as Map (keys)
|
||||||
|
@ -46,10 +46,11 @@ instance Page ArticlesList where
|
||||||
)
|
)
|
||||||
|
|
||||||
article :: Bool -> Article -> HtmlGenerator ()
|
article :: Bool -> Article -> HtmlGenerator ()
|
||||||
article raw (Article {body, title, urlPath}) =
|
article raw (Article {key, body, title}) = do
|
||||||
|
url <- ("/" </>) . (</> key <.> extension) <$> (Blog.get $path.$articlesPath)
|
||||||
article_ (do
|
article_ (do
|
||||||
header_ (do
|
header_ (do
|
||||||
aElem [href_ . pack $ "/" </> urlPath <.> extension] . h1_ $ toHtml title
|
aElem [href_ . pack $ url] . h1_ $ toHtml title
|
||||||
)
|
)
|
||||||
pre_ . toHtml $ unlines body
|
pre_ . toHtml $ unlines body
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,9 +58,9 @@ articlesLists (Collection {articlesFeatured, basePath, tag}) = do
|
||||||
|
|
||||||
generateArticles :: [Article] -> ReaderT Blog IO ()
|
generateArticles :: [Article] -> ReaderT Blog IO ()
|
||||||
generateArticles = mapM_ $ \article -> do
|
generateArticles = mapM_ $ \article -> do
|
||||||
filePath <- (</> urlPath article <.> "html") <$> (Blog.get $path.$root)
|
baseDir <- (</>) <$> (Blog.get $path.$root) <*> (Blog.get $path.$articlesPath)
|
||||||
(renderTextT $ page article)
|
(renderTextT $ page article)
|
||||||
>>= liftIO . TextIO.writeFile filePath
|
>>= liftIO . TextIO.writeFile (baseDir </> key article <.> "html")
|
||||||
|
|
||||||
generateCollection :: Collection -> ReaderT Blog IO ()
|
generateCollection :: Collection -> ReaderT Blog IO ()
|
||||||
generateCollection (Collection {articlesFeatured = []}) = return ()
|
generateCollection (Collection {articlesFeatured = []}) = return ()
|
||||||
|
|
|
@ -14,12 +14,10 @@ import Data.ByteString.Lazy (ByteString)
|
||||||
import Data.Map (Map, mapWithKey)
|
import Data.Map (Map, mapWithKey)
|
||||||
import qualified Data.Map as Map (filter, keys)
|
import qualified Data.Map as Map (filter, keys)
|
||||||
import qualified Data.Set as Set (elems, member)
|
import qualified Data.Set as Set (elems, member)
|
||||||
import System.FilePath.Posix ((</>), (<.>))
|
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
|
|
||||||
data ArticleExport = ArticleExport {
|
data ArticleExport = ArticleExport {
|
||||||
source :: String
|
title :: String
|
||||||
, title :: String
|
|
||||||
, bodyOffset :: Int
|
, bodyOffset :: Int
|
||||||
, metadata :: Map String String
|
, metadata :: Map String String
|
||||||
, tagged :: [String]
|
, tagged :: [String]
|
||||||
|
@ -56,8 +54,7 @@ instance ToJSON BlogDB where
|
||||||
|
|
||||||
export :: Blog -> String -> Article -> ArticleExport
|
export :: Blog -> String -> Article -> ArticleExport
|
||||||
export blog key article = ArticleExport {
|
export blog key article = ArticleExport {
|
||||||
source = "/" </> Article.urlPath article <.> "md"
|
title = Article.title article
|
||||||
, title = Article.title article
|
|
||||||
, bodyOffset = Article.bodyOffset article
|
, bodyOffset = Article.bodyOffset article
|
||||||
, metadata = Article.metadata article
|
, metadata = Article.metadata article
|
||||||
, tagged = Map.keys . Map.filter (Set.member key) $ Blog.tags blog
|
, tagged = Map.keys . Map.filter (Set.member key) $ Blog.tags blog
|
||||||
|
|
3
src/TODO
Normal file
3
src/TODO
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pre {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
Loading…
Reference in a new issue