<{!-- A quick demo of using WebMake to generate a news site, this time with sections. This is vaguely reminiscent of Wired News, or Slashdot without the comments. For this demo, we read the sections from the story text files, and use whatever sections they have defined. Normally I would imagine it would be better to define the section names in advance, in a list, then warn about stories that used an unknown section, but hey, this is a demo. ;) --}> <{!-- ------------------------------------------------------------------- --}> <{perl # create a ${all_stories} variable containing the list # of all text files just loaded. Trim off the .txt # at the end of each filename. Also create per-section # lists. # # Note that there will probably be a PerlCode library function # to do all this ;) my @all = (); my %sections = (); foreach my $pg (sorted_content_matching ("score title", "*.txt")) { my $sect = get_content ($pg . ".section"); $pg =~ s/\.txt$//; push (@all, $pg); push (@{$sections{$sect}}, $pg); } # make the list of all stories set_content ("all_stories", join (' ', @all)); # the list of all sections my @section_names = sort keys %sections; set_content ("all_sections", join (' ', @section_names)); # and each per-section story list foreach my $sect (@section_names) { set_content ("section_stories_$sect", join (' ', @{$sections{$sect}})); } ''; # this perl code produces no output }> <{!-- ------------------------------------------------------------------- --}> <{!-- Just as a demo, let's throw the story's abstract into the header. --}> $[this.title] <{!-- ------------------------------------------------------------------- --}>
  • [$[${item}.txt.section]] $[${item}.txt.title]

    $[${item}.txt.abstract]

    • <{perl make_list ('index_list_item', split (' ', get_content ("all_stories"))); }>
    <{!-- ------------------------------------------------------------------- --}> <{perl make_list ('index_list_item', split (' ', get_content ("section_stories_${sect}"))); }> <{!-- ------------------------------------------------------------------- --}> <{!-- BTW, in passing, note that this file uses a /story directory to store the stories, whereas the basic news site does not; the only change that needed to be made was the change to the file attribute below. Nothing else needed to be changed to do this! Cool eh? --}> ${header}${${pg}.txt}${footer} <{!-- ------------------------------------------------------------------- --}> ${header}${${sect}_index_chunk}${footer} ${header}${index_chunk}${footer}