Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement backend #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
implement backend
  • Loading branch information
Hadi committed Jan 26, 2025
commit fbff3b0e862de9b0641f2f8cfa33fcca0208dac5
Empty file added Backend/.env
Empty file.
12 changes: 12 additions & 0 deletions Backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const express = require('express');
const bodyParser = require('body-parser');
const searchRoutes = require('./routes/searchRoutes');
const app = express();

// Middleware
app.use(bodyParser.json());

// Routes
app.use('/api/search', searchRoutes);

module.exports = app;
Empty file.
Empty file.
108 changes: 108 additions & 0 deletions Backend/indexMarkdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const { Client } = require('@elastic/elasticsearch');
const fs = require('fs');
const path = require('path');

const client = new Client({ node: 'http://127.0.0.1:9200' });
const markdownDir = '../Frontend/docs';

async function createIndex() {
try {
await client.indices.create({
index: 'markdown-files',
body: {
mappings: {
properties: {
title: { type: 'text' },
content: { type: 'text' },
path: { type: 'keyword' },
},
},
},
});
console.log('Index "markdown-files" created.');
} catch (error) {
if (error.meta.body.error.type === 'resource_already_exists_exception') {
console.log('Index "markdown-files" already exists.');
} else {
throw error;
}
}
}

async function indexMarkdown(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const title = path.basename(filePath, '.md');
const documentId = path.relative(markdownDir, filePath);

await client.index({
index: 'markdown-files',
id: documentId,
body: {
title: title,
content: content,
path: filePath,
},
});

console.log(`Indexed file: ${filePath}`);
}

async function indexAllMarkdown() {
const files = fs.readdirSync(markdownDir);
for (const file of files) {
if (file.endsWith('.md')) {
await indexMarkdown(path.join(markdownDir, file));
}
}
console.log('All files indexed.');
}

async function indexAllMarkdownBulk() {
const files = fs.readdirSync(markdownDir);
const body = [];

for (const file of files) {
if (file.endsWith('.md')) {
const filePath = path.join(markdownDir, file);
const content = fs.readFileSync(filePath, 'utf8');
const title = path.basename(filePath, '.md');
const documentId = path.relative(markdownDir, filePath);

body.push(
{ index: { _index: 'markdown-files', _id: documentId } },
{
title: title,
content: content,
path: filePath,
}
);
}
}

const { body: bulkResponse } = await client.bulk({ refresh: true, body });

if (bulkResponse.errors) {
const erroredDocuments = [];
bulkResponse.items.forEach((action, i) => {
const operation = Object.keys(action)[0];
if (action[operation].error) {
erroredDocuments.push({
status: action[operation].status,
error: action[operation].error,
operation: body[i * 2],
document: body[i * 2 + 1],
});
}
});
console.log('Bulk indexing encountered errors:', erroredDocuments);
} else {
console.log('All files indexed successfully.');
}
}

async function main() {
await createIndex();
await indexAllMarkdownBulk(); // Or use indexAllMarkdown() for individual indexing
}

main().catch(console.error);
22 changes: 22 additions & 0 deletions Backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"watch": "node watcher.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.3",
"chokidar": "^4.0.3",
"cors": "^2.8.5",
"dotenv": "^16.4.7",
"elasticsearch": "^16.7.3",
"express": "^4.21.2"
}
}
Empty file added Backend/routes/searchRoutes.js
Empty file.
Empty file added Backend/server.js
Empty file.
Empty file.
Empty file added Backend/watcher.js
Empty file.
25 changes: 25 additions & 0 deletions Frontend/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# filtershekan.sbs


## add abbrivations:
add abbrivations in includes/abbrivations.md it will included automatically

## example elements:
docs/all_elements.md
https://filtershekan.sbs/all_elements

## disable comments:
add comments: false on page meta

## page title:
the first `#` will be used as page title.

## order pages in menu:
add numberp before file name to order them
increase the number by 10 to be able to easily add new page in between them in future

## add annoncce
Edit file `overrides/main.html`

## add icon
use this link: https://squidfunk.github.io/mkdocs-material/reference/icons-emojis/
17 changes: 17 additions & 0 deletions Frontend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


prepare:
pip install "mkdocs-material[imaging]==9.2.5" mkdocs-rss-plugin mkdocs-git-revision-date-localized-plugin mkdocs-git-authors-plugin mkdocs-awesome-pages-plugin mkdocs-nav-weight nltk mkdocs-include-markdown-plugin
pip install -U --force-reinstall git+https://github.com/hiddify/mkdocs-static-i18n git+https://github.com/hiddify/mkdocs git+https://github.com/hiddify/lunr.py
sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant

docs:
@mkdocs serve #--no-livereload

tw:
@npx tailwindcss -i ./input.css -o ./docs/assets/css/site.css

.PHONY: all test clean docs


idx = lunr(ref='location',fields=('title', 'text'),documents={'location':1},languages="fa",)
24 changes: 24 additions & 0 deletions Frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# روش‌های اتصال به اینترنت آزاد

در این مستندات سعی بر این که تمام روش های موثر برای اتصال به اینترنت آزاد جمع آوری گردد.
در نظر داشته باشید روش های بسیار متعددی و گوناگونی معرفی شده است .

# وب سایت های دانشنامه آزاد

[وب سایت فیلترشکن](https://filtershekan.sbs/)

[لیست سایر دانشنامه های آزاد](https://filtershekan.sbs/Knowledge_Base/)

# فهرست مطالب

برای دیدن فهرست به سایت زیر مراجعه کنید
<br>
https://filtershekan.sbs


# گرم یاد آوری یا نه من از یادت نمی کاهم

* به یاد یوسف قبادی
* به یاد سگارو
* [صحبت های سارینا اسماعیل زاده](https://www.youtube.com/watch?v=gpRnvFZ3vTU&t=52s)
* [مجیدرضا رهنورد](https://www.youtube.com/watch?v=N3Yo009a7Uc)
Loading