Skip to content
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
PORT=3000
FIREBASE_DATABASE_URL=
80 changes: 40 additions & 40 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
import js from '@eslint/js';
import globals from 'globals';
import importPlugin from 'eslint-plugin-import';
import js from "@eslint/js";
import globals from "globals";
import importPlugin from "eslint-plugin-import";

export default [
js.configs.recommended,
{
files: ['**/*.{js,mjs,cjs}'],
files: ["**/*.{js,mjs,cjs}"],
languageOptions: {
globals: globals.node,
ecmaVersion: 'latest',
sourceType: 'module'
ecmaVersion: "latest",
sourceType: "module"
},
plugins: {
import: importPlugin
},
rules: {
// Airbnb-style rules

'func-style': ['error', 'expression'],
"func-style": ["error", "expression"],

'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
'no-console': 'warn',
'no-var': 'error',
'prefer-const': 'error',
'prefer-arrow-callback': 'error',
'arrow-spacing': ['error', { 'before': true, 'after': true }],
'comma-dangle': ['error', 'never'],
'eol-last': ['error', 'always'],
'no-multiple-empty-lines': ['error', { 'max': 1 }],
'object-curly-spacing': ['error', 'always'],
'array-bracket-spacing': ['error', 'never'],
'space-before-blocks': 'error',
'keyword-spacing': ['error', { 'before': true, 'after': true }],
'space-infix-ops': 'error',
'no-trailing-spaces': 'error',
'eqeqeq': ['error', 'always'],
'no-multi-spaces': 'error',
'no-param-reassign': ['error', { 'props': false }],
'prefer-template': 'error',
'template-curly-spacing': ['error', 'never'],
'no-useless-concat': 'error',
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-console": "warn",
"no-var": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",
"arrow-spacing": ["error", { "before": true, "after": true }],
"comma-dangle": ["error", "never"],
"eol-last": ["error", "always"],
"no-multiple-empty-lines": ["error", { "max": 1 }],
"object-curly-spacing": ["error", "always"],
"array-bracket-spacing": ["error", "never"],
"space-before-blocks": "error",
"keyword-spacing": ["error", { "before": true, "after": true }],
"space-infix-ops": "error",
"no-trailing-spaces": "error",
"eqeqeq": ["error", "always"],
"no-multi-spaces": "error",
"no-param-reassign": ["error", { "props": false }],
"prefer-template": "error",
"template-curly-spacing": ["error", "never"],
"no-useless-concat": "error",

// Import rules (Airbnb-style)
'import/no-unresolved': 'off',
'import/named': 'error',
'import/default': 'error',
'import/namespace': 'error',
'import/no-duplicates': 'error',
'import/order': ['error', {
'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'never'
"import/no-unresolved": "off",
"import/named": "error",
"import/default": "error",
"import/namespace": "error",
"import/no-duplicates": "error",
"import/order": ["error", {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
"newlines-between": "never"
}]
}
}
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from './src/app.js';
import app from "./src/app.js";

const port = process.env.PORT || 3000;

Expand Down
15 changes: 9 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import path from 'path';
import { fileURLToPath } from 'url';
import express from 'express';
import path from "path";
import { fileURLToPath } from "url";
import express from "express";
import router from "./routes/route.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const app = express();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));

app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, "public")));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.use(router);

export default app;
86 changes: 86 additions & 0 deletions src/controllers/pagesController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs/promises';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const loadMockData = async () => {
const dataPath = path.join(__dirname, '..', 'data', 'mockData.json');
const rawData = await fs.readFile(dataPath, 'utf-8');
return JSON.parse(rawData);
};

export const getHomePage = async (req, res) => {
try {
const data = await loadMockData();
res.render('index', {
stats: data.stats,
features: data.features,
});
} catch {
res.status(500).send('Error loading page');
}
};

export const getDomainsPage = async (req, res) => {
try {
const data = await loadMockData();
res.render('domains', {
domains: data.domains,
});
} catch {
res.status(500).send('Error loading domains');
}
};

export const getSubdomainPage = async (req, res) => {
try {
const { domainId } = req.params;
const data = await loadMockData();
const domain = data.domains.find((d) => d.id === domainId);

if (!domain) {
return res.status(404).send('Domain not found');
}

res.render('subdomain', { domain });
} catch {
res.status(500).send('Error loading subdomain');
}
};

export const getTopicsPage = async (req, res) => {
try {
const { subdomainId } = req.params;
const data = await loadMockData();
const topic = data.topics[subdomainId];

if (!topic) {
return res.status(404).send('Topics not found');
}

res.render('topicsPage', {
topic,
subdomainId,
});
} catch {
res.status(500).send('Error loading topics');
}
};

export const getSuggestTopicPage = async (req, res) => {
try {
const { domainId, subdomainId } = req.params;
const data = await loadMockData();
const topic = data.topics[subdomainId];

res.render('suggestTopic', {
domainId,
subdomainId,
subdomainName: topic ? topic.name : subdomainId,
});
} catch {
res.status(500).send('Error loading page');
}
};
51 changes: 51 additions & 0 deletions src/controllers/topicsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs/promises";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export const getTopics = async (req, res) => {
try {
const { category } = req.params;
const dataPath = path.join(__dirname, "..", "data", "topicsData.json");
const rawData = await fs.readFile(dataPath, "utf-8");
const allTopics = JSON.parse(rawData);

const categoryData = allTopics[category];

if (!categoryData) {
return res.status(404).send("Topic category not found");
}

res.render("topics", {
categoryName: categoryData.name,
subtitle: categoryData.subtitle,
topics: categoryData.topics,
categorySlug: category
});
} catch (error) {
console.error("Error loading topics:", error);
res.status(500).send("Error loading topics");
}
};

export const getAllCategories = async (req, res) => {
try {
const dataPath = path.join(__dirname, "..", "data", "topicsData.json");
const rawData = await fs.readFile(dataPath, "utf-8");
const allTopics = JSON.parse(rawData);

const categories = Object.keys(allTopics).map((key) => ({
slug: key,
name: allTopics[key].name,
subtitle: allTopics[key].subtitle,
topicCount: allTopics[key].topics.length
}));

res.render("categories", { categories });
} catch (error) {
console.error("Error loading categories:", error);
res.status(500).send("Error loading categories");
}
};
Loading