Skip to content

Commit b8fa7f6

Browse files
committed
Updated contributions page generation script to use 3.x list and to properly handle listings with multiple categories.
1 parent 2970f44 commit b8fa7f6

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

generate/contributions.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
//$benchmark_start = microtime_float();
1111

1212
//Grab the contributions data from the text file
13-
$contributions = "\n".file_get_contents('../contrib_generate/contributions.txt');
13+
$contributions = "\n".file_get_contents('../contrib_generate/contribs.txt');
1414
//$contributions .= file_get_contents('../contrib_generate/legacy.txt');
1515

1616
//Split the contributions text file by contribution type
17-
$types = "/(\ntool|\nlibrary|\nmode)/";
17+
$types = "/(\ntool|\nlibrary|\nmode|\nexamples)/";
1818
$flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY;
1919
$items = preg_split( $types, $contributions, -1, $flags);
2020

2121
$byType = array(
22-
'library' => array(),
23-
'tool' => array(),
24-
'mode' => array()
22+
'library' => array(),
23+
'tool' => array(),
24+
'mode' => array(),
25+
'examples' => array()
2526
);
2627

2728
for($i = 0; $i < count($items); $i+=2){
@@ -34,7 +35,7 @@
3435
$count = 0;
3536
foreach($contents as &$entity){
3637
$entity = preg_split( "/(\n)/", $entity);
37-
array_shift($entity);
38+
array_shift($entity);
3839
array_pop($entity);
3940

4041
foreach($entity as &$line){
@@ -77,14 +78,15 @@ function anchorSafe($input){
7778
//Push all libraries into array sorted by category
7879
$categories = array();
7980
foreach($clean['library'] as $library){
80-
array_push($categories, $library['category']);
81+
$lib_categories = array_map('trim', explode(',', $library['categories']));
82+
$categories = array_merge($categories, $lib_categories);
8183
}
8284
$categories = array_unique($categories);
8385
sort($categories);
8486

8587
//Create a nav from each category (Except Legacy)
8688
$librariesHTML = '<div class="contributions">'."\n".'<div class="categories">'."\n";
87-
foreach($categories as $category){
89+
foreach($categories as $category){
8890
if($category != 'Legacy'){
8991
$librariesHTML .= "\t".'<a href="#'.anchorSafe($category).'">'.$category.'</a><br>'."\n";
9092
}
@@ -97,12 +99,12 @@ function anchorSafe($input){
9799
$librariesHTML .= '<div id="'.anchorSafe($category).'">'."\n\t";
98100
$librariesHTML .= '<h4>'.$category.'</h4>'."\n";
99101
$librariesHTML .= "\t<ul>\n";
100-
$libs = array_filter($clean['library'], function($obj) use($category){ return $obj['category'] == $category; });
101-
102+
$libs = array_filter($clean['library'], function($obj) use($category){ return strpos($obj['categories'], $category) !== false; });
103+
102104
foreach($libs as $lib) {
103105
$librariesHTML .= "\t\t<li>\n";
104106
$librariesHTML .= "\t\t\t".'<h5><a href="'.$lib['url'].'">'.$lib['name'].'</a></h5>'."\n";
105-
$librariesHTML .= "\t\t\t".'<span>by '.linkParse($lib['authorList']).'</span>'."\n";
107+
$librariesHTML .= "\t\t\t".'<span>by '.linkParse($lib['authors']).'</span>'."\n";
106108
$librariesHTML .= strlen(trim($lib['sentence'])) ? "\t\t\t".'<p>'.linkParse($lib['sentence']).'</p>'."\n" : "\n";
107109
$librariesHTML .= "\t\t</li>\n";
108110
}
@@ -113,13 +115,13 @@ function anchorSafe($input){
113115
}
114116

115117
//List out the Legacy Libraries
116-
//$legacy = array_filter($clean['library'], function($obj) { return $obj['category'] == 'Legacy'; });
118+
//$legacy = array_filter($clean['library'], function($obj) { return $obj['categories'] == 'Legacy'; });
117119
//$librariesHTML .= "<div class='legacy'>\n\t<h4>Legacy Libraries</h4>\n";
118120
//$librariesHTML .= "\t<p>The libraries in this category haven't been updated by their creators to be compatible with the Processing 2 library manager and/or updated to work with Processing 2. We hope to have all libraries working with Processing 2; if one of your favorite libraries hasn't been updated, we encourage you to contact the library creator or to update it yourself and share it. Instructions for creating a Processing 2 library <a href='https://github.com/processing/processing/wiki'>are on the Processing GitHub site.</a>.</p>\n\t<ul>\n";
119121
//foreach($legacy as $lib){
120122
// $librariesHTML .= "\t\t<li>\n";
121123
// $librariesHTML .= "\t\t\t".'<h5><a href="'.$lib['url'].'">'.$lib['name'].'</a></h5>'."\n";
122-
// $librariesHTML .= "\t\t\t".'<span>by '.linkParse($lib['authorList']).'</span>'."\n";
124+
// $librariesHTML .= "\t\t\t".'<span>by '.linkParse($lib['authors']).'</span>'."\n";
123125
// $librariesHTML .= "\t\t</li>\n";
124126
//}
125127
//$librariesHTML .= "</ul></div></div>";
@@ -130,9 +132,9 @@ function anchorSafe($input){
130132
//Write LibrariesHTML to libraries.html file
131133
$file_dir = CONTENTDIR.'static/';
132134
$file_name = strip_tags('libraries.html');
133-
$file = $file_dir.$file_name;
135+
$file = $file_dir.$file_name;
134136

135-
$create_file = fopen($file, "w+");
137+
$create_file = fopen($file, "w+");
136138
$chmod = chmod($file, 0755);
137139
fwrite($create_file, $librariesHTML);
138140
fclose($create_file);
@@ -146,16 +148,16 @@ function anchorSafe($input){
146148
//$legacy = "<div class='legacy'>\n<h4>Legacy Tools</h4>\n<p>The tools in this category haven't been updated by their creators to be compatible with the Processing 2 library manager and/or updated to work with Processing 2. We hope to have all tools working with Processing 2; if one of your favorite tools hasn't been updated, we encourage you to contact the tool creator or to update it yourself and share it. Instructions for creating a Processing 2 library <a href='https://github.com/processing/processing/wiki'>are on the Processing GitHub site.</a>.</p>\n<ul>\n";
147149

148150
foreach($clean['tool'] as $tool){
149-
//if($tool['category'] != 'Legacy'){
151+
//if($tool['categories'] != 'Legacy'){
150152
$toolsHTML .= "\t<li>\n";
151153
$toolsHTML .= "\t\t".'<h5><a href="'.$tool['url'].'">'.$tool['name'].'</a></h5>'."\n";
152-
$toolsHTML .= "\t\t".'<span>by '.linkParse($tool['authorList']).'</span>'."\n";
154+
$toolsHTML .= "\t\t".'<span>by '.linkParse($tool['authors']).'</span>'."\n";
153155
$toolsHTML .= strlen(trim($tool['sentence'])) ? "\t\t".'<p>'.linkParse($tool['sentence']).'</p>'."\n" : "\n";
154156
$toolsHTML .= "\t</li>\n";
155157
//} else {
156158
// $legacy .= "\t<li>\n";
157159
// $legacy .= "\t\t".'<h5><a href="'.$tool['url'].'">'.$tool['name'].'</a></h5>'."\n";
158-
// $legacy .= "\t\t".'<span>by '.linkParse($tool['authorList']).'</span>'."\n";
160+
// $legacy .= "\t\t".'<span>by '.linkParse($tool['authors']).'</span>'."\n";
159161
// $legacy .= "\t</li>\n";
160162
//}
161163
}
@@ -166,12 +168,12 @@ function anchorSafe($input){
166168

167169
//Write toolsHTML to tools.html file
168170
$file_name = strip_tags('tools.html');
169-
$file = $file_dir.$file_name;
171+
$file = $file_dir.$file_name;
170172

171-
$create_file = fopen($file, "w+");
173+
$create_file = fopen($file, "w+");
172174
$chmod = chmod($file, 0755);
173175
fwrite($create_file, $toolsHTML);
174176
fclose($create_file);
175177

176178

177-
?>
179+
?>

0 commit comments

Comments
 (0)