Skip to content

Commit a70efb5

Browse files
Merge pull request #9 from VictorGotsenko/Step08
Step08 - done! Refactor readme.md
2 parents f7ba00e + 43e50fb commit a70efb5

9 files changed

Lines changed: 58 additions & 5 deletions

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22
[![Actions Status](https://github.com/VictorGotsenko/java-project-72/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/VictorGotsenko/java-project-72/actions)
33
[![Page Validator](https://github.com/VictorGotsenko/java-project-72/actions/workflows/JavaCI.yml/badge.svg)](https://github.com/VictorGotsenko/java-project-72/actions/workflows/JavaCI.yml)
44
## Description
5-
Page Validator is enabled on link [https://page-validator.onrender.com](https://pagesanalyzer.onrender.com)
5+
#### Application for analyzing links for SEO suitability, is enable on <a href="https://pagesanalyzer.onrender.com" target="_blank">Link Page Analyzer</a>
6+
Приложение – сайт, который анализирует указанные страницы на SEO пригодность.
7+
8+
![Main page screen](app/img/page1.png)
9+
![Site page screen](app/img/page2.png)
10+
11+
### How to use:
12+
```shell
13+
make build-run
14+
```
15+
16+
+ Used technologies:
17+
- Frontend: Bootstrap, JTE
18+
- Backend: Java, Javalin, LOMBOK, PostgreSQL, H2database, unirest-java, jsoup
19+
- Tests: JUnit, MockWebServer

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ dependencies {
4747
// Unirest Java
4848
implementation("com.konghq:unirest-java:3.14.5")
4949

50+
// jsoup HTML parser library @ https://jsoup.org/
51+
implementation("org.jsoup:jsoup:1.21.1")
52+
5053
// Tests
5154
testImplementation("org.junit.jupiter:junit-jupiter:6.0.0-M1")
5255
testImplementation(platform("org.junit:junit-bom:6.0.0-M1"))

app/img/page1.png

47.7 KB
Loading

app/img/page2.png

72.6 KB
Loading

app/src/main/java/hexlet/code/controller/UrlCheckController.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import kong.unirest.Unirest;
2525
import kong.unirest.UnirestException;
2626
import lombok.extern.slf4j.Slf4j;
27+
import org.jsoup.Jsoup;
28+
import org.jsoup.nodes.Document;
2729

2830
@Slf4j
2931
public final class UrlCheckController {
@@ -35,12 +37,18 @@ public static void check(Context ctx) throws SQLException {
3537
Long urlId = ctx.pathParamAsClass("id", Long.class).get();
3638
Url url = UrlRepository.find(urlId)
3739
.orElseThrow(() -> new NotFoundResponse("Entity with id = " + urlId + " not found"));
38-
log.info("Получен ID: {}", urlId);
40+
log.info("Got URL ID: {}", urlId);
3941
try {
4042
HttpResponse<String> response = Unirest.get(url.getName()).asString();
43+
Document document = Jsoup.parse(response.getBody());
44+
4145
int statusCode = response.getStatus();
46+
log.info("Response getStatus: {}", statusCode);
47+
String title = document.title();
48+
String h1 = document.select("h1").text();
49+
String description = document.select("meta[name=description]").attr("content");
4250

43-
UrlCheck urlCheck = new UrlCheck(urlId, statusCode, "title", "h1", "descrip");
51+
UrlCheck urlCheck = new UrlCheck(urlId, statusCode, title, h1, description);
4452
UrlCheckRepository.save(urlCheck);
4553

4654
log.info("check saved");

app/src/main/java/hexlet/code/repository/UrlCheckRepository.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hexlet.code.repository;
22

33
import hexlet.code.model.UrlCheck;
4+
import lombok.extern.slf4j.Slf4j;
45

56
import java.sql.Connection;
67
import java.sql.PreparedStatement;
@@ -13,7 +14,7 @@
1314
import java.util.List;
1415
import java.util.Map;
1516

16-
17+
@Slf4j
1718
public final class UrlCheckRepository {
1819
private UrlCheckRepository() {
1920
// for Sonar Warning
@@ -41,6 +42,7 @@ public static void save(UrlCheck urlCheck) throws SQLException {
4142
}
4243
} catch (SQLException e) {
4344
e.printStackTrace();
45+
log.info("Error in UrlCheckRepository.save ", e);
4446
}
4547
}
4648

@@ -67,6 +69,7 @@ public static List<UrlCheck> findById(Long urlId) throws SQLException {
6769
result.add(urlCheck);
6870
}
6971
} catch (SQLException e) {
72+
log.info("Error in UrlCheckRepository.findById ", e);
7073
e.printStackTrace();
7174
}
7275
return result;
@@ -92,6 +95,7 @@ public static Map<Long, UrlCheck> getLastestChecks() throws SQLException {
9295
result.put(urlId, urlCheck);
9396
}
9497
} catch (SQLException e) {
98+
log.info("Error in UrlCheckRepository.getLastestChecks ", e);
9599
e.printStackTrace();
96100
}
97101
return result;

app/src/main/resources/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CREATE TABLE url_checks (
1414
status_code INT,
1515
title VARCHAR(100),
1616
h1 VARCHAR(100),
17-
description VARCHAR(255),
17+
description TEXT,
1818
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
1919
FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE -- foreign key with cascade delete
2020
);

app/src/main/resources/templates/index.jte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,20 @@ content = @`
2727
</div>
2828
</div>
2929
</div>
30+
<div class="col-md-10 col-lg-8 mx-auto text-white">
31+
<br>
32+
<br>
33+
<br>
34+
<p>SEO, или поисковая оптимизация (от англ. Search Engine Optimization) - это комплекс мер и действий,
35+
направленных на улучшение видимости сайта в поисковых системах, таких как Google и Яндекс, с целью
36+
увеличения
37+
органического (бесплатного) трафика на сайт. Простыми словами, SEO помогает сделать ваш сайт более
38+
привлекательным для поисковых роботов и, как следствие, для пользователей, которые ищут информацию в
39+
интернете.
40+
</p>
41+
<br>
42+
<p style="text-align:right;">Успехов! Ж;-) С наилучшими, Виктор
43+
</p>
44+
45+
</div>
3046
`)

app/src/main/resources/templates/layout/page.jte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,13 @@
6262

6363
${content}
6464
</main>
65+
<footer class="footer">
66+
<div class="container">
67+
<div class="text-center text-muted">
68+
created by
69+
<a href="https://github.com/VictorGotsenko" target="_blank">Victor Gotsenko</a>
70+
</div>
71+
</div>
72+
</footer>
6573
</body>
6674
</html>

0 commit comments

Comments
 (0)