-
Notifications
You must be signed in to change notification settings - Fork 0
/
techport.html
113 lines (95 loc) · 4.85 KB
/
techport.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Space Technology</title>
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="css/index.css">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<!-- fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lekton&family=MedievalSharp&family=Poppins&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<nav style="--bs-breadcrumb-divider: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='%236c757d'/%3E%3C/svg%3E");"
aria-label="breadcrumb">
<ol class="breadcrumb mt-5">
<li class="breadcrumb-item"><a href="index.html" class="hyperlinkblock text-white">Home</a></li>
<li class="breadcrumb-item text-white" aria-current="page">Discover</li>
<li class="breadcrumb-item text-white" aria-current="page">Space Technologies</li>
</ol>
</nav>
<h1 class="text-center my-5 text-white">Space Technologies</h1>
<div class="container">
<div class="row" id="results"></div>
</div>
</div>
<script>
// Define the API endpoint URL
const apiUrl = 'https://images-api.nasa.gov/search?q=rocket';
var request = new XMLHttpRequest();
request.open('GET', apiUrl, true);
request.addEventListener('load', function () {
if (request.status >= 200 && request.status < 400) {
var response = JSON.parse(request.responseText);
displayResults(response.collection.items);
} else {
console.log("Error in network request: " + request.statusText);
}
});
request.send(null);
// Function to truncate a string to a specified number of words
function truncateToWords(text, limit) {
// Split the text into words
var words = text.split(' ');
// Check if the text contains more words than the limit
if (words.length > limit) {
// Join the first 'limit' words back together with spaces
return words.slice(0, limit).join(' ') + '...'; // Add '...' to indicate truncation
}
// If the text contains equal or fewer words than the limit, return it as is
return text;
}
// Set a word limit (e.g., 20 words)
var wordLimit = 50;
function displayResults(items) {
var resultsDiv = document.getElementById('results');
if (items.length === 0) {
resultsDiv.innerHTML = '<p>No results found.</p>';
return;
}
var html = '';
items.forEach(function (item) {
if (item.links) {
var thumbnailLink = item.links[0].href;
var title = item.data[0].title;
var description = item.data[0].description;
var truncatedDescription = truncateToWords(description, wordLimit);
html += '<div class="col-md-4 mb-4" data-bs-theme="dark">';
html += '<div class="card">';
html += '<img src="' + thumbnailLink + '" class="card-img-top" style="height: 280px;" alt="' + title + '">';
html += '<div class="card-body" style="height: 280px;">';
html += '<h5 class="card-title">' + title + '</h5>';
html += '<p class="card-text">' + truncatedDescription + '</p>';
html += '</div>';
html += '</div>';
html += '</div>';
}
});
resultsDiv.innerHTML = html;
}
</script>
<!-- Include Bootstrap JS and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>