Created
January 15, 2013 23:39
-
-
Save ToJans/4543202 to your computer and use it in GitHub Desktop.
Going to convert my blog to github-pages using an erlang-app :/
This file contains hidden or 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
-module(blogconverter) | |
-export([convert/2,convert/3]) | |
convert(UrlFrom,UrlTo) -> | |
convert(UrlFrom,UrlTo,jekyll); | |
convert(UrlFrom,UrlTo,Format) -> | |
savePosts(fetchPosts(UrlFrom),UrlTo,Format). | |
fetchPosts(Url) -> | |
Data=fetchPostsData(Url), | |
ToPosts(getPostsFormat(Url,Data),Data). | |
toPosts(rss,Data) -> | |
% TODO: parse XML here | |
. | |
savePosts(Posts,Url,Format=jekyll) -> | |
% TODO: save posts here | |
fetchPostsData(Url) -> | |
fetchPostsData(getUrlType(Url),Url); | |
fetchPostsData(web,Url)-> | |
inets:start(), | |
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, Body}} = httpc:request(get, Url,{}, []}, [], []), | |
inets:stop(), | |
Body. | |
getUrlType(Path) -> | |
case re:run(Path,"^http(s)?://.+$") of | |
match -> web; | |
_ -> file | |
end. | |
getPostsFormat(Path,_ResourceData) -> | |
case re:run(Path,"^.+rss") of | |
match -> rss | |
end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment