news.gp



Creator information
Current maintainer :Max Maischein
Author(s) :Max Maischein
Recipe homepage :<none>

Version history
The documentation file was last modified on Tue Nov 29 18:22:58 2016.

Overview
news.gp is a (not so) simple news system.
Compatible Genpage Versions
Version 1.0.3 and above.
Syntax
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.

News files

The format of the news files is as follows :


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)
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.
One special field is the ID field, which should contain an unique ID that identifies the news item on the page. If the ID field is not given, news() automagically creates a unique ID for it. The use of the ID field is to link (for example) headlines to their body.
Another special field is the DATE field. If it is not present, news() substitutes the creation date of the corresponding .news file. Deviating from the "one-field-per-line" rule is only the BODY field, every line after the "BODY:" line also goes into the BODY field - this allows for easier creation of long news.

Theme files

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 -->


In both sections, there will be some special replacements :
In the %_NEWS_BODY_% section, <!-- _NEWS_ ITEMS --> will be replaced by the list of items.
In the %_NEWS_ITEM_% section, <!-- _NEWS_ itemname --> will be replaced by the text after itemname: in the item file (or some witty text, if itemname is not present).


Examples

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 :

  1. Create a directory content/news/ and create at least one file with the extension .news there.
  2. At the location in your page where you want the news to be placed, put the following HTML :
    <!-- _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) :


Great news todaySat Jun 12 17:16:15 1999
Hello again ! Today's news are not really that new. But you never know :)
Hello World !Yesterday
Hello world ! This is the first news that you will see. This item was produced yesterday. Even more interesting stuff will follow. Also, hotlinks can be embedded into news.
Full news

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.

Creating a page with all news

If you want to create a page that contains all news items (and thus can become quite large), simply use the following code :


<!-- _GP_ news( "$root/content/news/", -1, "$root/news.themes/default.gpnewstheme" ) -->
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).


To-do List

Known Bugs
None known :)

Back to Top


This page generated using Genpage - Version: 1.0.7 on Wed Nov 30 16:34:11 2016

© Max Maischein
1999