forked from codeaprendiz/learn_devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-readme.php
59 lines (49 loc) · 2.07 KB
/
update-readme.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
$header_row = "| Tasks | Skills | High Level Objective |\n|-------|--------|----------------------|";
$rows = array();
foreach (glob("taskset/task-*") as $task_folder) {
$file_contents = file_get_contents("$task_folder/ReadMe.md");
$pattern_for_objectives = '/\*\*High Level Objectives\*\*(.*?)\*\*Skills\*\*/s';
if (preg_match($pattern_for_objectives, $file_contents, $matches_for_objectives)) {
$matched_lines_between_pattern_for_objectives = explode("\n", $matches_for_objectives[1]);
$objectives = '';
foreach ($matched_lines_between_pattern_for_objectives as $line) {
$line = trim($line);
$line = str_replace('- ', '<li>', $line);
if (!empty($line)) {
// $line = '`'.$line.'`';
// $objectives .= ($objectives ? ', ' : '') . $line;
$objectives .= ($objectives ? '<br> ' : '') . $line;
}
}
} else {
echo "\nNo matches found.";
}
$patter_for_skills = '/\*\*Skills\*\*(.*?)\*\*Version Stack\*\*/s';
if (preg_match($patter_for_skills, $file_contents, $matches_for_keywords)) {
$matched_lines_between_pattern_for_keywords = explode("\n", $matches_for_keywords[1]);
$skills = '';
foreach ($matched_lines_between_pattern_for_keywords as $line) {
$line = trim($line);
$line = str_replace('-', '', $line);
if (!empty($line)) {
$line = '`'.$line.'`';
$skills .= ($skills ? ', ' : '') . $line;
// $skills .= ($skills ? '<br> ' : '') . $line;
}
}
} else {
echo "No matches found.";
}
$task_name = basename($task_folder);
$task_name = substr($task_name, 5, 3);
$row = "| [$task_name]($task_folder) | $skills | $objectives |";
array_push($rows, $row);
}
$table = $header_row . "\n" . implode("\n", $rows);
echo $table;
file_put_contents("ReadMe.md", $table);
# https://github.com/nvuillam/markdown-table-formatter
# npm install markdown-table-formatter -g
exec('markdown-table-formatter');
?>