diff --git a/pages/blog/[slug].tsx b/components/Presentational/SingleBlog/Blog.tsx similarity index 73% rename from pages/blog/[slug].tsx rename to components/Presentational/SingleBlog/Blog.tsx index 9bf0fe98..2925de02 100644 --- a/pages/blog/[slug].tsx +++ b/components/Presentational/SingleBlog/Blog.tsx @@ -1,18 +1,11 @@ import { useEffect } from 'react' -import Head from 'next/head' import { useRouter } from 'next/router' -import fs from 'fs' import Image from 'next/image' import { LinkedinShareButton, FacebookShareButton } from 'next-share' import { Box, Container, Stack, Typography } from '@mui/material' -import { joinUsLinkIcons, newsAndBlogs } from '../../data/data' -import { BlogPostWithContent, Blog } from '../../types/interfaces' -import { BLOGS_PATH } from '../../utils/constants' -import { - getMarkDownSingleData, - getMarkdownSinglePath, -} from '../../utils/markdown' -import MarkdownText from '../../components/MarkdownText' +import { joinUsLinkIcons, newsAndBlogs } from '../../../data/data' +import MarkdownText from '../../MarkdownText' +import { BlogPost } from '../../../types/interfaces' import Prism from 'prismjs' import 'prismjs/themes/prism-tomorrow.css' import 'prismjs/components/prism-python' @@ -25,30 +18,25 @@ import 'prismjs/components/prism-typescript' import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace' import 'prismjs/components/prism-markup-templating' -export default function BlogDetailPage({ - frontmatter: { title, date, cover_image, author }, - content, -}: BlogPostWithContent) { +export default function Blog({ blog }: { blog: BlogPost }) { const router = useRouter() useEffect(() => { Prism.highlightAll() }, []) + if (!blog) return
Loading...
+ return ( <> - -
\n
\n
\n
\n
\npython3 -m venv myenv
\nsource myenv/bin/activate
\npip install django
django-admin startproject project
cd project
python3 manage.py startapp app
pip install scrapy
scrapy startproject scraper
cd scraper
\nscrapy genspider website_crawler domain
\n
\nimport os
\nimport sys
\nimport django
\n\\# Django Integration
\n\nsys.path.append(os.path.dirname(os.path.abspath(".")))
\nos.environ["DJANGO_SETTINGS_MODULE"] = "project.settings"
\ndjango.setup()
\nITEM_PIPELINES = {
\n"scraper.pipelines.ScraperPipeline": 300,
\n}
\nscrapy crawl scraper
Counter: {counter}
\n \n \n{data.description}
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\nNext.js is a popular open-source framework for building web applications with React. Next.js provides a streamlined development experience by offering server-side rendering (SSR), static site generation (SSG), and client-side rendering capabilities.
With Next.js, developers can build modern, dynamic web applications that are optimized for performance and SEO. It simplifies the process of creating server-rendered React applications by providing a structured setup and routing system.
Next.js 13 comes with new directory structure for routes and apis along with some new buildin layout and loading files.
Use this command to create a new next.js app with new version: npx create-next-app@latest
During installation, it will show you following prompts:
> What is your project named? my-app> Would you like to use TypeScript with this project? No / Yes> Would you like to use ESLint with this project? No / Yes> Would you like to use Tailwind CSS with this project? No / Yes> Would you like to use `src/` directory with this project? No / Yes> Use App Router (recommended)? No / Yes> Would you like to customize the default import alias? No / Yes
Next.js now ships with TypeScript, ESLint, and Tailwind CSS configuration by default.
These are the major upgrades added in this new version are these:
“Next.js provides a TypeScript-first development experience for building your React application.
It comes with built-in TypeScript support for automatically installing the necessary packages and configuring the proper settings. As well as a TypeScript Plugin for your editor.”
Read More: Typescript in Next.js 13+
Next.js 13 includes updated file routing with the new directory. The app directory introduces a new layout, loading structure as well as several new features and improvements.
The directory structure has introduces few changes due to the new routing mechanism. Each path in the route has a dedicated directory with a page.tsx file that serves as the content entry point in Next.js 13.
We can also add layout.tsx, error.tsx and loading.tsx files inside each folder within /app directory.
{post.frontmatter.excerpt}
+{post.meta_description}
- + @@ -71,12 +66,30 @@ const Blog = ({ blogs }: MDContent) => { export default Blog export async function getStaticProps() { - const blogFiles = fs.readdirSync(path.join(BLOGS_PATH)) - const blogs = getMarkdownAllData(blogFiles, BLOGS_PATH, fs) - - return { - props: { - blogs: blogs.sort(sortByDate), - }, + try { + const headers = { + Authorization: `token ${process.env.NEXT_PUBLIC_ERP_AUTH_TOKEN}`, + } + const response = await axios.get( + `${process.env.NEXT_PUBLIC_ERP_BASEPATH}/api/resource/Blog%20Post?fields=[%22*%22]`, + { + headers, + } + ) + const blogs = response.data.data?.filter( + (blog: BlogPost) => blog?.published === 1 + ) + return { + props: { + blogs: blogs, + }, + } + } catch (error) { + console.error('Error fetching blog data:', error) + return { + props: { + blogs: [], + }, + } } } diff --git a/pages/index.tsx b/pages/index.tsx index 19fa78d6..bd64619f 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -27,13 +27,15 @@ import { BlogPost, MDContent, Product } from '../types/interfaces' import { sortByDate, sortByIndex } from '../utils/sort' import { getMarkdownAllData, getMarkDownSingleData } from '../utils/markdown' import { - BLOGS_PATH, + // BLOGS_PATH, SERVICES_PATH, TESTIMONIALS_PATH, ABOUT_US_PATH, PRODUCT_PATH, } from '../utils/constants' import { FEATURES } from '../data/features' +// import { data } from '../data/blogdata' +import axios from 'axios' export default function Home({ blogs, @@ -138,12 +140,12 @@ export default function Home({{blog.frontmatter.excerpt}
+{blog.blog_intro}
- + Read More