|Current maintainer :||Max Maischein|
|Author(s) :||Max Maischein|
|Recipe homepage :||<none>|
|Compatible Genpage Versions|
news( aNewsdirectory )
news( aNewsdirectory, aMaxItems )
news( aNewsdirectory, aMaxItems, aNewsThemefile )
news() looks at all files with the extension .news in the directory given through aNewsdirectory, formats each with a template and returns the whole thing. The items are sorted by the creation date of their file. The maximum number of news items can also be specified, as can the output format through a theme file. I use news.gp to maintain the news, FAQ and history pages for my site.
aNewsdirectory must be the name of a directory in which at least one file with the extension .news should be found (and it should be readable ...).
aMaxItems is an optional parameter that gives the maximum number of items that should be presented on the page. If this parameter is undefined, a default of 5 items is assumed. If you want all items to be presented on a page, you must supply a negative value (for example -1) to aMaxItems.
aNewsThemefile is the second optional parameter. It contains the name of the template file for both, the whole news body and for each item. A set of prefabricated themes are already supplied, some are direct rips of their originals (Slashdot, Freshmeat) while others are creations of my own. If this parameter is undefined, a default template (embedded into the source code) is used. News themes historically reside in $root/news.themes, but you are free to move them somewhere else.
The format of the news files is as follows :
All the fields can be used in the news theme to have locations for the date, email, homepage etc., it is a good idea to keep track of the required fields for each news theme. news() also works if a field is required in the theme but missing in the .news file.
Fieldname:Field text (only one line) OtherFieldname:Other field text (only one line) ... BODY:Body of the news More body ... (even without the BODY: prefix, because BODY collects all this)
The format of the theme files is as follows :
%_NEWS_BODY% <!-- This is the section that surrounds all the items --> %_NEWS_ITEM_% <!-- This section will be repeated for every item -->
First of all, the file news.gp must be included in some content by using
<!-- _GP_ recipe( "news.gp" ) -->.
Setting up all the stuff for news() can be done in two steps :
<!-- _GP_ news( "$root/content/news" ) -->
Let's assume that there is a directory $root/content/news and that in that directory, there are two files, today.news and yesterday.news. Let's further assume that the filedate of today.news is younger than the filedate of yesterday.news. The contents of yesterday.news are :
TITLE:Hello world ! DATE:Yesterday BODY:Hello world ! This is the first news that you will see. This item was produced yesterday. Even more interesting stuff will follow. Also, <A href="http://www.freddyfrog.com/">hotlinks</A> can be embedded into news.
And let's also assume the contents of today.news are :
TITLE:Great news today ! BODY:Hello again ! Today's news are not really that new. But you never know :)
Note that in today.news, the DATE field is missing. news() will substitute the file's date and time,
if the date field is missing.
Let's now look at the following HTML excerpt to be used in a .content file :
<A name="news"></A> <H2>News</H2> <!-- _GP_ include "$root/include/news.gp" --> <!-- _GP_ news( "$root/content/news/",4, "$root/news.themes/default.gpnewstheme" ) --> <A href="completenews.html">Full news</A>
The above code will produce the following, nice news (HTML output ommitted for brevity) :
There are other news themes, which make it possible to create headlines from the news (by simply omitting the _NEWS_ BODY field), to create a FAQ style list (by combining the headlines and then the news bodies in one page) and many more. For a FAQ or headlines, there might be another interesting recipe, toc(), which creates a table of contents from all headings in one page.
If you want to create a page that contains all news items (and thus can become quite large), simply use the following code :
There is no way (yet) to make news() and Genpage spit out several pages with 5 items each, and I don't consider this useful (yet).
<!-- _GP_ news( "$root/content/news/", -1, "$root/news.themes/default.gpnewstheme" ) -->