Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-excerpt #14

Open
manuel-rubio opened this issue Jul 11, 2015 · 0 comments
Open

Auto-excerpt #14

manuel-rubio opened this issue Jul 11, 2015 · 0 comments

Comments

@manuel-rubio
Copy link

Hi, when I wrote posts in Wordpress and later in Octopress, I always use the auto-excerpt option to add a tag like <!--more--> to the text to indicate what part should be the excerpt for the post. I was searching something similar in the code of lambdpad and I found nothing, so, I wrote this:

add_autoblurb(Proplists) ->
    case {
        plist:value("blurb", Proplists, undefined),
        plist:value('__file__', Proplists, undefined)
    } of
        {undefined,File} ->
            [{"blurb",get_autoblurb(File)}|Proplists];
        {Blurb,_File} ->
            [{"blurb",Blurb}|Proplists]
    end.

get_autoblurb(File) ->
    {ok, Content} = file:read_file(File),
    case binary:split(Content, <<"\n\n">>) of
        [_,Text] ->
            case binary:split(Text, <<"<!--more-->">>) of
                [Blurb,_] ->
                    Blurb;
                [NoBlurbDefined] ->
                    NoBlurbDefined
            end;
        [OnlyText] ->
            <<>>
    end.

Note that I use blurb entry for this :-P It pass to the function the metadata from file and extract the first paragraphs from the file, until <!--more--> tag or all the text if the tag is not defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant