Commit e530c99eb5

e530c99eb5bfaacf29b8666ee561b737bf62c023

parent: 58ee925fe7

Unsigned

cmc <hello@cleberg.net> · 2023-06-01 02:14 UTC

implement remaining API endpoints

Layout: unified · split

index.php +53 −10
@@ -11,7 +11,7 @@ if (empty($elements[0])) {
1111 );
1212 echo_html(
1313 $GLOBALS['full_domain'] . '/best/',
14 'The top 30 stories from Hacker News. Proxied by hn.',
14 'The top stories from Hacker News, proxied by hn.',
1515 'hn',
1616 $html_output
1717 );
@@ -23,31 +23,75 @@ if (empty($elements[0])) {
2323 'Top'
2424 );
2525 echo_html(
26 $GLOBALS['full_domain'] . '/best/',
27 'The top 30 stories from Hacker News. Proxied by hn.',
26 $GLOBALS['full_domain'] . '/top/',
2827 'hn',
2928 $html_output
3029 );
3130 break;
3231
3332 case 'best':
34 echo 'best';
33 $html_output = get_stories(
34 'https://hacker-news.firebaseio.com/v0/beststories.json?limitToFirst=30&orderBy="$key"',
35 'Best'
36 );
37 echo_html(
38 $GLOBALS['full_domain'] . '/best/',
39 'The best 30 stories from Hacker News, proxied by hn.',
40 'hn',
41 $html_output
42 );
3543 break;
3644
3745 case 'new':
38 echo 'new';
46 $html_output = get_stories(
47 'https://hacker-news.firebaseio.com/v0/newstories.json?limitToFirst=30&orderBy="$key"',
48 'New'
49 );
50 echo_html(
51 $GLOBALS['full_domain'] . '/new/',
52 'The newest 30 stories from Hacker News, proxied by hn.',
53 'hn',
54 $html_output
55 );
3956 break;
4057
4158 case 'ask':
42 echo 'ask';
59 $html_output = get_stories(
60 'https://hacker-news.firebaseio.com/v0/askstories.json?limitToFirst=30&orderBy="$key"',
61 'Ask'
62 );
63 echo_html(
64 $GLOBALS['full_domain'] . '/ask/',
65 'The latest 30 asks from Hacker News, proxied by hn.',
66 'hn',
67 $html_output
68 );
4369 break;
4470
4571 case 'show':
46 echo 'show';
72 $html_output = get_stories(
73 'https://hacker-news.firebaseio.com/v0/showstories.json?limitToFirst=30&orderBy="$key"',
74 'Show'
75 );
76 echo_html(
77 $GLOBALS['full_domain'] . '/show/',
78 'The latest 30 show stories from Hacker News, proxied by hn.',
79 'hn',
80 $html_output
81 );
4782 break;
4883
4984 case 'job':
50 echo 'job';
85 $html_output = get_stories(
86 'https://hacker-news.firebaseio.com/v0/jobstories.json?limitToFirst=30&orderBy="$key"',
87 'Job'
88 );
89 echo_html(
90 $GLOBALS['full_domain'] . '/job/',
91 'The latest 30 job posts from Hacker News, proxied by hn.',
92 'hn',
93 $html_output
94 );
5195 break;
5296
5397 default:
@@ -64,8 +108,7 @@ if (empty($elements[0])) {
64108 * @param string $inline_title The <h1> title to use in the HTML
65109 * @return string $html_output The formatted HTML result of stories from the API
66110 */
67function get_stories($api_url, $inline_title)
68{
111function get_stories($api_url, $inline_title) {
69112 $response_raw = file_get_contents($api_url);
70113 $response = json_decode($response_raw, true);
71114