Skip to content

Commit 583c9f6

Browse files
committed
ref #main: style fixes
1 parent e090fb9 commit 583c9f6

File tree

3 files changed

+131
-20
lines changed

3 files changed

+131
-20
lines changed

functions.php

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
<?php
2+
3+
function d8_set_permalink_structure() {
4+
// Check if the permalink structure is already set to 'post name'
5+
if ( get_option('permalink_structure') !== '/%postname%/' ) {
6+
// Set the permalink structure to 'post name'
7+
global $wp_rewrite;
8+
$wp_rewrite->set_permalink_structure('/%postname%/');
9+
$wp_rewrite->flush_rules();
10+
}
11+
}
12+
13+
add_action('after_switch_theme', 'd8_set_permalink_structure');
14+
215
function terminal_theme_scripts() {
316
wp_enqueue_style('terminal-style', get_template_directory_uri() . '/style.css');
417
// Enqueue your script
@@ -8,13 +21,17 @@ function terminal_theme_scripts() {
821
wp_localize_script('terminal-theme-script', 'wpData', array(
922
'baseUrl' => get_site_url(),
1023
'siteTitle' => get_bloginfo('name'), // Retrieves the WordPress site title
11-
'siteDescription' => get_bloginfo('description'), // Retrieves the WordPress site description
24+
'siteDescription' => get_bloginfo('description'), // Retrieves the WordPress site description
25+
'memoryUsage' => size_format(memory_get_usage(), 2),
26+
'currentTheme' => wp_get_theme()->get('Name'),
27+
'serverSoftware' => $_SERVER['SERVER_SOFTWARE'],
28+
'ipAddress' => $_SERVER['REMOTE_ADDR'],
29+
'requestTime' => $_SERVER['REQUEST_TIME'],
1230
));
1331
}
1432

1533
add_action('wp_enqueue_scripts', 'terminal_theme_scripts');
1634

17-
1835
function terminal_setup() {
1936
add_theme_support( 'title-tag' );
2037
add_theme_support( 'automatic-feed-links' );
@@ -25,15 +42,15 @@ function terminal_setup() {
2542

2643

2744
function terminal_meta_description() {
45+
46+
$description = '';
47+
2848
if (is_single() || is_page()) {
2949
// For single posts or pages
3050
$description = get_the_excerpt();
3151
} elseif (is_home() || is_front_page()) {
3252
// For the home/front page
3353
$description = get_bloginfo('description');
34-
} else {
35-
// Default description
36-
$description = 'Your default description here';
3754
}
3855

3956
return esc_attr(strip_tags($description));

script.js

+62-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@ const config = {
22
baseUrl: wpData.baseUrl, // This will be dynamically set to the WordPress base URL,
33
siteTitle: wpData.siteTitle,
44
siteDescription: wpData.siteDescription,
5+
currentTheme: wpData.currentTheme,
6+
memoryUsage: wpData.memoryUsage,
7+
serverSoftware: wpData.serverSoftware,
8+
ipAddress: wpData.ipAddress,
9+
requestTime: wpData.requestTime,
510

611
};
712

813
const history = document.getElementById('history');
914

10-
welcomeScreen();
15+
document.addEventListener('DOMContentLoaded', (event) => {
16+
welcomeScreen();
17+
});
1118

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+
} );
1525
}
1626

17-
document.addEventListener('DOMContentLoaded', (event) => {
18-
autoExecuteCommandFromURL();
19-
});
27+
2028

2129
async function autoExecuteCommandFromURL() {
2230
const url = window.location.href;
@@ -123,6 +131,9 @@ function appendCommandInput() {
123131

124132
async function getTitle() {
125133

134+
const totalPosts = await getTotalPosts();
135+
const totalCategories = await getTotalCategories();
136+
126137
const domain = new URL(config.baseUrl).hostname;
127138
const emailAddress = `hello@${domain}`;
128139

@@ -131,14 +142,30 @@ async function getTitle() {
131142
history.innerHTML += `<div class="command-output">$</div>`;
132143
history.innerHTML += `<div class="command-output">$ System information as of ${new Date().toLocaleString()}</div>`;
133144
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>`;
142169
}
143170

144171

@@ -351,3 +378,23 @@ function openImagePopup(imageUrl) {
351378

352379
document.body.appendChild(popup);
353380
}
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+
}

style.css

+47
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,51 @@ body, html {
126126

127127
.share-links a:hover {
128128
text-decoration: underline; /* Adds underline on hover */
129+
}
130+
131+
table.no-spacing {
132+
border-spacing:0; /* Removes the cell spacing via CSS */
133+
border-collapse: collapse; /* Optional - if you don't want to have double border where cells touch */
134+
}
135+
136+
pre {
137+
background-color: #f5f5f5; /* Light grey background */
138+
border: 1px solid #ddd; /* Light border */
139+
border-left: 3px solid #f36d33; /* Accent border */
140+
color: #666; /* Darker text color for readability */
141+
page-break-inside: avoid;
142+
font-family: monospace;
143+
font-size: 15px; /* Larger font size */
144+
line-height: 1.6;
145+
margin-bottom: 1.6em;
146+
max-width: 100%;
147+
overflow: auto;
148+
padding: 1em 1.5em;
149+
display: block;
150+
word-wrap: break-word;
151+
}
152+
153+
code {
154+
font-family: monospace;
155+
font-size: 0.9em; /* Slightly smaller font size */
156+
}
157+
@media (max-width: 600px) {
158+
pre {
159+
padding: 0.5em; /* Smaller padding on small screens */
160+
}
161+
}
162+
163+
h1, h2, h3, h4, h5, h6 {
164+
color: #fff; /* White color for headers */
165+
margin-top: 1em;
166+
margin-bottom: 0.5em;
167+
}
168+
169+
p {
170+
margin-bottom: 1em;
171+
}
172+
173+
ul, ol {
174+
margin-left: 20px;
175+
margin-bottom: 1em;
129176
}

0 commit comments

Comments
 (0)