Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
[![Actions Status](https://github.com/VictorGotsenko/java-project-72/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/VictorGotsenko/java-project-72/actions)
[![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)
## Description
Page Validator is enabled on link [https://page-validator.onrender.com](https://pagesanalyzer.onrender.com)
#### Application for analyzing links for SEO suitability, is enable on <a href="https://pagesanalyzer.onrender.com" target="_blank">Link Page Analyzer</a>
Приложение – сайт, который анализирует указанные страницы на SEO пригодность.

![Main page screen](app/img/page1.png)
![Site page screen](app/img/page2.png)

### How to use:
```shell
make build-run
```

+ Used technologies:
- Frontend: Bootstrap, JTE
- Backend: Java, Javalin, LOMBOK, PostgreSQL, H2database, unirest-java, jsoup
- Tests: JUnit, MockWebServer
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ dependencies {
// Unirest Java
implementation("com.konghq:unirest-java:3.14.5")

// jsoup HTML parser library @ https://jsoup.org/
implementation("org.jsoup:jsoup:1.21.1")

// Tests
testImplementation("org.junit.jupiter:junit-jupiter:6.0.0-M1")
testImplementation(platform("org.junit:junit-bom:6.0.0-M1"))
Expand Down
Binary file added app/img/page1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/img/page2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions app/src/main/java/hexlet/code/controller/UrlCheckController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

@Slf4j
public final class UrlCheckController {
Expand All @@ -35,12 +37,18 @@ public static void check(Context ctx) throws SQLException {
Long urlId = ctx.pathParamAsClass("id", Long.class).get();
Url url = UrlRepository.find(urlId)
.orElseThrow(() -> new NotFoundResponse("Entity with id = " + urlId + " not found"));
log.info("Получен ID: {}", urlId);
log.info("Got URL ID: {}", urlId);
try {
HttpResponse<String> response = Unirest.get(url.getName()).asString();
Document document = Jsoup.parse(response.getBody());

int statusCode = response.getStatus();
log.info("Response getStatus: {}", statusCode);
String title = document.title();
String h1 = document.select("h1").text();
String description = document.select("meta[name=description]").attr("content");

UrlCheck urlCheck = new UrlCheck(urlId, statusCode, "title", "h1", "descrip");
UrlCheck urlCheck = new UrlCheck(urlId, statusCode, title, h1, description);
UrlCheckRepository.save(urlCheck);

log.info("check saved");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hexlet.code.repository;

import hexlet.code.model.UrlCheck;
import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.PreparedStatement;
Expand All @@ -13,7 +14,7 @@
import java.util.List;
import java.util.Map;


@Slf4j
public final class UrlCheckRepository {
private UrlCheckRepository() {
// for Sonar Warning
Expand Down Expand Up @@ -41,6 +42,7 @@ public static void save(UrlCheck urlCheck) throws SQLException {
}
} catch (SQLException e) {
e.printStackTrace();
log.info("Error in UrlCheckRepository.save ", e);
}
}

Expand All @@ -67,6 +69,7 @@ public static List<UrlCheck> findById(Long urlId) throws SQLException {
result.add(urlCheck);
}
} catch (SQLException e) {
log.info("Error in UrlCheckRepository.findById ", e);
e.printStackTrace();
}
return result;
Expand All @@ -92,6 +95,7 @@ public static Map<Long, UrlCheck> getLastestChecks() throws SQLException {
result.put(urlId, urlCheck);
}
} catch (SQLException e) {
log.info("Error in UrlCheckRepository.getLastestChecks ", e);
e.printStackTrace();
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CREATE TABLE url_checks (
status_code INT,
title VARCHAR(100),
h1 VARCHAR(100),
description VARCHAR(255),
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE -- foreign key with cascade delete
);
16 changes: 16 additions & 0 deletions app/src/main/resources/templates/index.jte
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ content = @`
</div>
</div>
</div>
<div class="col-md-10 col-lg-8 mx-auto text-white">
<br>
<br>
<br>
<p>SEO, или поисковая оптимизация (от англ. Search Engine Optimization) - это комплекс мер и действий,
направленных на улучшение видимости сайта в поисковых системах, таких как Google и Яндекс, с целью
увеличения
органического (бесплатного) трафика на сайт. Простыми словами, SEO помогает сделать ваш сайт более
привлекательным для поисковых роботов и, как следствие, для пользователей, которые ищут информацию в
интернете.
</p>
<br>
<p style="text-align:right;">Успехов! Ж;-) С наилучшими, Виктор
</p>

</div>
`)
8 changes: 8 additions & 0 deletions app/src/main/resources/templates/layout/page.jte
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,13 @@

${content}
</main>
<footer class="footer">
<div class="container">
<div class="text-center text-muted">
created by
<a href="https://github.com/VictorGotsenko" target="_blank">Victor Gotsenko</a>
</div>
</div>
</footer>
</body>
</html>
Loading