@@ -2,21 +2,29 @@ const config = {
2
2
baseUrl : wpData . baseUrl , // This will be dynamically set to the WordPress base URL,
3
3
siteTitle : wpData . siteTitle ,
4
4
siteDescription : wpData . siteDescription ,
5
+ currentTheme : wpData . currentTheme ,
6
+ memoryUsage : wpData . memoryUsage ,
7
+ serverSoftware : wpData . serverSoftware ,
8
+ ipAddress : wpData . ipAddress ,
9
+ requestTime : wpData . requestTime ,
5
10
6
11
} ;
7
12
8
13
const history = document . getElementById ( 'history' ) ;
9
14
10
- welcomeScreen ( ) ;
15
+ document . addEventListener ( 'DOMContentLoaded' , ( event ) => {
16
+ welcomeScreen ( ) ;
17
+ } ) ;
11
18
12
- function welcomeScreen ( ) {
13
- getTitle ( ) ;
14
- executeCommand ( 'help' ) ;
19
+ async function welcomeScreen ( ) {
20
+ getTitle ( ) . then ( r => {
21
+ executeCommand ( 'help' ) . then ( r => {
22
+ autoExecuteCommandFromURL ( ) ;
23
+ } ) ;
24
+ } ) ;
15
25
}
16
26
17
- document . addEventListener ( 'DOMContentLoaded' , ( event ) => {
18
- autoExecuteCommandFromURL ( ) ;
19
- } ) ;
27
+
20
28
21
29
async function autoExecuteCommandFromURL ( ) {
22
30
const url = window . location . href ;
@@ -123,6 +131,9 @@ function appendCommandInput() {
123
131
124
132
async function getTitle ( ) {
125
133
134
+ const totalPosts = await getTotalPosts ( ) ;
135
+ const totalCategories = await getTotalCategories ( ) ;
136
+
126
137
const domain = new URL ( config . baseUrl ) . hostname ;
127
138
const emailAddress = `hello@${ domain } ` ;
128
139
@@ -131,14 +142,30 @@ async function getTitle() {
131
142
history . innerHTML += `<div class="command-output">$</div>` ;
132
143
history . innerHTML += `<div class="command-output">$ System information as of ${ new Date ( ) . toLocaleString ( ) } </div>` ;
133
144
history . innerHTML += `<div class="command-output">$</div>` ;
134
- history . innerHTML += `<div class="command-output">$ System load: [Data Unavailable] Processes: [Data Unavailable]</div>` ;
135
- history . innerHTML += `<div class="command-output">$ Usage of /: [Data Unavailable] Users logged in: [Data Unavailable]</div>` ;
136
- history . innerHTML += `<div class="command-output">$ Memory usage: [Data Unavailable] IP address: [Data Unavailable]</div>` ;
137
- history . innerHTML += `<div class="command-output">$ Swap usage: [Data Unavailable]</div>` ;
138
- history . innerHTML += `<div class="command-output">$</div>` ;
139
- history . innerHTML += `<div class="command-output">$ [Number] articles can be explored.</div>` ;
140
- history . innerHTML += `<div class="command-output">$ [Number] categories to discover.</div>` ;
141
- history . innerHTML += `<div class="command-output">$</div>` ;
145
+ history . innerHTML += `
146
+ <table class="no-spacing">
147
+ <tr>
148
+ <td>$ System software:</td>
149
+ <td>${ config . serverSoftware } </td>
150
+ <td>Total Articles:</td>
151
+ <td>${ totalPosts } </td>
152
+ </tr>
153
+ <tr>
154
+ <td>$ Request Time:</td>
155
+ <td>${ config . requestTime } </td>
156
+ <td>Total Categories:</td>
157
+ <td>${ totalCategories } </td>
158
+ </tr>
159
+ <tr>
160
+ <td>$ Memory usage:</td>
161
+ <td>${ config . memoryUsage } </td>
162
+ <td>IP address:</td>
163
+ <td>${ config . ipAddress } </td>
164
+ </tr>
165
+ </table>
166
+ ` ;
167
+ history . innerHTML += `<div class="command-output">$ Current theme: ${ config . currentTheme } </div>` ;
168
+ history . innerHTML += `<div class="command-output">$</div>` ;
142
169
}
143
170
144
171
@@ -351,3 +378,23 @@ function openImagePopup(imageUrl) {
351
378
352
379
document . body . appendChild ( popup ) ;
353
380
}
381
+
382
+ async function getTotalPosts ( ) {
383
+ try {
384
+ const response = await fetch ( `${ config . baseUrl } /wp-json/wp/v2/posts?per_page=1` ) ;
385
+ return response . headers . get ( 'X-WP-Total' ) ;
386
+ } catch ( error ) {
387
+ console . error ( 'Error fetching total posts:' , error ) ;
388
+ return 'Unavailable' ;
389
+ }
390
+ }
391
+
392
+ async function getTotalCategories ( ) {
393
+ try {
394
+ const response = await fetch ( `${ config . baseUrl } /wp-json/wp/v2/categories?per_page=1` ) ;
395
+ return response . headers . get ( 'X-WP-Total' ) ;
396
+ } catch ( error ) {
397
+ console . error ( 'Error fetching total categories:' , error ) ;
398
+ return 'Unavailable' ;
399
+ }
400
+ }
0 commit comments