├── .env
├── .gitignore
├── .nowignore
├── README.md
├── components
├── AddButton.js
├── CommentBox.js
├── Footer.js
├── HackCard.js
├── Header.js
├── Layout.js
├── NotifyMeModal.js
├── PaginationBox.js
├── PostFilters.js
└── SearchInput.js
├── config
└── global.js
├── now.json
├── package.json
├── pages
├── _app.js
├── contributors.js
├── index.js
├── post.js
├── search.js
├── sitemap.js
└── tag.js
├── server.js
├── sitemap.js
├── static
├── images
│ ├── daily-hack-favicon.png
│ ├── daily-hack-image.png
│ ├── daily-hack-logo.png
│ └── header-left-vector.png
├── sitemap.xml
└── style.scss
└── yarn.lock
/.env:
--------------------------------------------------------------------------------
1 | DAILYHACK_GITHUB_API="https://dailyhack.glitch.me/"
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | package-lock.json
3 | .next/
--------------------------------------------------------------------------------
/.nowignore:
--------------------------------------------------------------------------------
1 | .next
2 | node_modules
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | DailyHack
8 |
9 |
10 |
11 | 💡 :rocket:
12 |
13 |
14 | Website: https://dailyhack.now.sh/
15 |
16 |
17 | It's a place where people share the daily hacks they use during development to make their life easy. So, Do you have any hack to submit?
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | ## What’s In This Document
26 |
27 | - [About DailyHack](#-about-dailyhack)
28 | - [How to Add tricks](#-how-to-add-tricks)
29 | - [How to Contribute](#-how-to-contribute)
30 | - [Thanks to Our Contributors](#-thanks-to-our-contributors)
31 | - [License](#license)
32 |
33 |
34 |
35 | ## 📖 About DailyHack
36 |
37 | DailyHack is just an Idea about sharing the **hacks/tricks/shortcuts** we use in our daily life to develop and fix the things quick and smart way. It's a community of makers and geeks from around the world. Anyone can share their methods with other makers and developers.
38 |
39 |
40 |
41 | ## ✍ How to add tricks
42 |
43 | We are using the [GitHub Issue System](https://github.com/mddanishyusuf/dailyhack/issues) as a CMS. So, it's easy to add your tricks. Just create an issue and write your hack into an editor and submit. After you submit the author/editors will set the tags to your issues and it will show [on the website](https://dailyhack.xyz/).
44 |
45 |
46 |
47 | ## 🤝 How to Contribute
48 |
49 | Adding tricks is a big contribution to the open-source community. The website and the code in this repository is Open Source. So, you can make any improvements or changes you desire.
50 |
51 | [List of Contributors](https://dailyhack.xyz/contributors)
52 |
53 |
54 |
55 | ### Website Build With
56 |
57 | - **Next.js**- For SSR, Front-end I use [Styled JSX](https://nextjs.org/blog/styling-next-with-styled-jsx).
58 | - **GitHub Issues:** As a CMS for tricks
59 | - **Glitch:** A layer on the GitHub API to secure access_token
60 | - **Zeit:** To host the application
61 |
62 |
63 |
64 | ## 💜 Thanks to Our Contributors
65 |
66 | Thanks to our many contributors and friends who give their time to add tricks.
67 |
68 |
69 |
70 | ## License
71 |
72 | [](https://creativecommons.org/publicdomain/zero/1.0/)
73 |
--------------------------------------------------------------------------------
/components/AddButton.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link';
2 | import { PlusSquare } from 'react-feather';
3 |
4 | const AddButton = () => (
5 |
46 | )
47 |
48 | export default AddButton;
--------------------------------------------------------------------------------
/components/CommentBox.js:
--------------------------------------------------------------------------------
1 | import React, {useEffect, useState} from 'react';
2 | import axios from 'axios';
3 | import moment from 'moment'
4 | import Markdown from 'markdown-to-jsx';
5 | import {GITHUB_ENDPOIINT_LOCAL} from '../config/global'
6 |
7 | const HyperLink = ({ children, ...props }) => (
8 | {children}
9 | );
10 |
11 | const Comments = function(props){
12 | const {comments} = props;
13 |
14 | return (
15 |
16 |
Do you have any comment on this tricks? then let the author know about that.
comment here
17 | {
18 | comments.length > 0
19 | ?
20 |
21 | {comments.map((comment, key)=> {
22 | return(
23 |
24 |
25 |
26 |
27 |
28 |
29 |
{comment.user.login}
30 |
{moment(comment.created_at).fromNow()}
31 |
32 |
33 |
34 | {comment.body}
44 |
45 |
46 |
47 | )
48 | })}
49 |
50 | : 'This post have comments'
51 | }
52 |
88 |
89 | )
90 | }
91 |
92 | const CommentBox = function(props){
93 |
94 | const [comments, setComments] = useState([])
95 |
96 | useEffect(()=> {
97 | axios.get(`${GITHUB_ENDPOIINT_LOCAL}/issues/${props.single_issue.number}/comments`).then(res=>{
98 | setComments(res.data)
99 | })
100 | },[])
101 |
102 | return (
103 |
104 |
105 |
106 | {
107 | comments.length > 0
108 | ?
109 | :
Do you have any comment on this tricks? then let the author know about that.
comment here
110 | }
111 |
112 |
132 |
133 | )
134 | }
135 |
136 | export default CommentBox;
--------------------------------------------------------------------------------
/components/Footer.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 | import { Twitter, GitHub, Users, Info, HelpCircle } from 'react-feather';
3 |
4 | const Footer = function(props) {
5 | return (
6 |
94 | )
95 | }
96 |
97 | export default Footer;
98 |
--------------------------------------------------------------------------------
/components/HackCard.js:
--------------------------------------------------------------------------------
1 | import Markdown from 'markdown-to-jsx';
2 | import getSlug from 'speakingurl'
3 | import Link from 'next/link';
4 | import { Tag, Heart, MessageSquare, Twitter, Facebook } from 'react-feather';
5 | import moment from 'moment'
6 |
7 | const HyperLink = ({ children, ...props }) => (
8 | {children}
9 | );
10 |
11 | const HackCard = (props) => {
12 | const issue = props.single_issue
13 | return (
14 |
15 |
16 |
17 |
18 |
19 |
{issue.user.login}
20 |
{moment(issue.created_at).fromNow()}
21 |
22 |
23 |
24 |
25 | {props.router.asPath !== '/' ?
{issue.title} :
{issue.title} }
26 |
{issue.body}
36 |
37 |
38 |
39 |
40 |
41 | {issue.labels !== undefined ? issue.labels.map(label => {
42 | return(
43 | #{label.name}
44 | )
45 | }): ''}
46 |
47 |
48 |
49 |
50 |
56 |
57 |
58 |
59 |
217 |
218 | )
219 | }
220 | export default HackCard
--------------------------------------------------------------------------------
/components/Header.js:
--------------------------------------------------------------------------------
1 | import {Fragment} from 'react';
2 | import Link from 'next/link'
3 | import { withRouter } from 'next/router'
4 | import { Twitter, GitHub, Users, Bell, Coffee, Rss } from 'react-feather';
5 | import AddButton from './AddButton'
6 | import NotifyMeModal from './NotifyMeModal';
7 | import PostFilters from './PostFilters';
8 |
9 |
10 | const Header = (props) => {
11 | return(
12 |
13 | {/*
*/}
14 |
15 |
16 |
17 |
18 |
28 |
29 |
30 |
31 | {props.router.asPath === "/" ?
32 |
33 |
34 |
A Community of Makers and Geeks
35 |
It's a place where people share there daily hack they use in their developments. So, Do you have any hack?
36 |
37 |
38 |
39 |
40 |
41 | : ""}
42 |
43 |
141 |
142 |
143 | )}
144 |
145 | export default withRouter(Header);
--------------------------------------------------------------------------------
/components/Layout.js:
--------------------------------------------------------------------------------
1 | import {Fragment} from 'react';
2 | import Head from 'next/head';
3 |
4 | import Header from './Header';
5 | import Footer from './Footer';
6 |
7 | const Layout = props => {
8 | return(
9 |
10 |
11 |
12 |
13 |
{props.title}
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
38 |
39 |
40 |
41 |
{props.children}
42 |
43 |
58 |
59 | )
60 | }
61 |
62 | export default Layout;
--------------------------------------------------------------------------------
/components/NotifyMeModal.js:
--------------------------------------------------------------------------------
1 | import { Bell, XSquare } from 'react-feather';
2 |
3 | function NotifyMeModal(){
4 | return(
5 |
6 |
7 |
Close
8 |
Voilà! Notify Me.
9 |
Hey, You want to notify by GitHub whenever there is new tricks. Then it's Easy just go to this Project Repository and click on `Watch` + `Star`. That's it.
10 |
11 |
12 |
To Subscibe
13 |
14 |
15 |
16 |
To Appreciate
17 |
18 |
19 |
20 |
21 |
113 |
114 | )
115 | }
116 |
117 | export default NotifyMeModal;
--------------------------------------------------------------------------------
/components/PaginationBox.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 | import {PER_PAGE} from '../config/global'
3 |
4 | function PaginationBox(props){
5 | const activePage = props.active_page
6 | const numberOfPages = Math.ceil(props.total_issues / PER_PAGE)
7 | const paginationArray = Array.from(Array(numberOfPages).keys())
8 | return(
9 |
10 |
11 | {paginationArray.map(number => {
12 | return(
13 |
14 | {number+1 === parseInt(activePage) ? {number+1} : {number+1} }
15 |
16 |
17 | )
18 | })}
19 |
20 |
48 |
49 | )
50 | }
51 |
52 | export default PaginationBox;
--------------------------------------------------------------------------------
/components/PostFilters.js:
--------------------------------------------------------------------------------
1 | import {useState, useEffect} from 'react';
2 | import axios from 'axios';
3 | import Link from 'next/link'
4 |
5 | import {GLITCH_ENDPOINT} from '../config/global'
6 | import SearchInput from './SearchInput'
7 |
8 | function PostFilters(){
9 |
10 | const [tags, setTags] = useState([])
11 |
12 | useEffect(()=>{
13 | axios.get(GLITCH_ENDPOINT + '/tags').then(res=>{
14 | setTags(res.data)
15 | })
16 | },[])
17 | return(
18 |
19 |
20 | {tags.map((tag, key)=>{
21 | if(tag.name !== 'dailyhack'){
22 | return(
23 | #{tag.name}
24 | )
25 | }
26 | })}
27 |
28 |
29 |
62 |
63 | )
64 | }
65 |
66 | export default PostFilters;
--------------------------------------------------------------------------------
/components/SearchInput.js:
--------------------------------------------------------------------------------
1 | import {useState, useEffect} from 'react';
2 | import axios from 'axios';
3 | import Router from 'next/router'
4 |
5 | import {GITHUB_SEARCH_ENDPOIINT, GLITCH_ENDPOINT} from '../config/global'
6 |
7 | function SearchInput(props){
8 |
9 | const [searchQuery, setSearchQuery] = useState(props.query)
10 |
11 | const setQuery = (e) => {
12 | setSearchQuery(e.target.value)
13 | }
14 |
15 | const searchIssues = (e) => {
16 | e.preventDefault()
17 | var q = searchQuery.trim().split(' ').join('+')
18 | Router.push(`/search/${q}`)
19 | }
20 |
21 | return(
22 |
48 | )
49 | }
50 |
51 | export default SearchInput;
--------------------------------------------------------------------------------
/config/global.js:
--------------------------------------------------------------------------------
1 | export const GITHUB_ENDPOIINT_LOCAL = "https://api.github.com/repos/mddanishyusuf/dailyhack";
2 |
3 | export const GITHUB_SEARCH_ENDPOIINT = "https://api.github.com/search/issues";
4 |
5 | export const DAILYHACK_GITHUB_API = "https://api.github.com/"
6 |
7 | export const GLITCH_ENDPOINT = "https://dailyhack.glitch.me"
8 |
9 | export const PER_PAGE = 10
--------------------------------------------------------------------------------
/now.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "builds": [{ "src": "package.json", "use": "@now/next" }],
4 | "routes": [
5 | { "src": "/post/(?[a-z0-9-_]+-)(?[0-9]+)", "dest": "/post?number=$number&slug=$slug", "headers": {"cache-control": "max-age=1800"} },
6 | { "src": "/page/(?[0-9]+)", "dest": "/index?page_number=$page_number", "headers": {"cache-control": "max-age=1800"} },
7 | { "src": "/", "dest": "/index", "headers": {"cache-control": "max-age=1800"} },
8 | { "src": "/contributors", "dest": "/contributors", "headers": {"cache-control": "max-age=1800"} },
9 | { "src": "/tag/(?[a-z]+)", "dest": "/tag?tag_name=$tag_name", "headers": {"cache-control": "max-age=1800"} },
10 | { "src": "/search/(?[a-z0-9+]+)", "dest": "/search?keywords=$keywords", "headers": {"cache-control": "max-age=1800"} },
11 | { "src": "/sitemap.xml", "dest": "/server.js"}
12 | ]
13 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "dailyhack",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "dev": "node server.js",
8 | "build": "next build",
9 | "start": "NODE_ENV=production node server.js",
10 | "now-build": "next build"
11 | },
12 | "keywords": [],
13 | "author": "",
14 | "license": "ISC",
15 | "dependencies": {
16 | "@zeit/next-sass": "^1.0.1",
17 | "axios": "^0.18.0",
18 | "cacheable-response": "^1.4.2",
19 | "express": "^4.16.4",
20 | "fs": "0.0.1-security",
21 | "isomorphic-unfetch": "^3.0.0",
22 | "markdown-to-jsx": "^6.9.3",
23 | "moment": "^2.24.0",
24 | "next": "^9.3.2",
25 | "next-router-events": "^2.1.0",
26 | "node-sass": "^4.11.0",
27 | "now": "^14.2.3",
28 | "react": "^16.8.5",
29 | "react-dom": "^16.8.5",
30 | "react-feather": "^1.1.6",
31 | "speakingurl": "^14.0.1",
32 | "styled-jsx": "^3.2.1"
33 | },
34 | "devDependencies": {
35 | "dotenv": "^7.0.0"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pages/_app.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import App, {Container} from 'next/app'
3 | import Link from 'next/link'
4 | import Router from 'next/router'
5 | import routerEvents from 'next-router-events'
6 |
7 |
8 | export default class MyApp extends App {
9 |
10 | constructor(props){
11 | super(props)
12 |
13 | this.state = {
14 | progress: false,
15 | isCancelled: false
16 | }
17 |
18 | routerEvents.on('routeChangeStart', (url) => {
19 | !this.isCancelled && this.setState({progress: true})
20 | })
21 | routerEvents.on('routeChangeComplete', () => {
22 | !this.isCancelled && this.setState({progress: false})
23 | })
24 | routerEvents.on('routeChangeError', () => {
25 | console.log('error')
26 | })
27 | }
28 |
29 | componentWillUnmount() {
30 | this.isCancelled = true;
31 | }
32 |
33 | static async getInitialProps ({ Component, router, ctx }) {
34 | let pageProps = {}
35 |
36 | if (Component.getInitialProps) {
37 | pageProps = await Component.getInitialProps(ctx)
38 | }
39 |
40 | return {pageProps}
41 | }
42 |
43 | render () {
44 | const {Component, pageProps} = this.props
45 | return (
46 |
47 | {this.state.progress ?
: ''}
48 |
49 |
50 |
120 |
121 | )
122 | }
123 | }
--------------------------------------------------------------------------------
/pages/contributors.js:
--------------------------------------------------------------------------------
1 | import {Fragment} from 'react';
2 | import Layout from '../components/Layout';
3 | import fetch from 'isomorphic-unfetch';
4 | import { GLITCH_ENDPOINT} from '../config/global'
5 |
6 | function ContributorCard(props) {
7 | return (
8 |
9 |
10 |
11 |
Contributors.
12 |
{props.contributors.length} Members
13 |
These are the makers, geeks, developers. If you have any hack then your welcome to the community.
14 |
Join Community
15 |
16 | {props.contributors.map(cont => (
17 |
18 |
19 |
20 |
21 |
22 |
23 |
{cont.user.login}
24 |
{cont.issues.length} {cont.issues.length === 1 ? 'trick' : 'tricks'}
25 |
26 |
27 |
28 |
29 | ))}
30 |
31 |
106 |
107 | )
108 | }
109 |
110 | function Contributors(props){
111 | return(
112 |
113 |
114 |
115 |
116 |
117 | )
118 | }
119 |
120 | Contributors.getInitialProps = async function(){
121 | const url = GLITCH_ENDPOINT + '/contributors'
122 | const result = await fetch(url)
123 | const data = await result.json()
124 |
125 | return {
126 | contributors: data
127 | }
128 | }
129 |
130 | export default Contributors;
131 |
--------------------------------------------------------------------------------
/pages/index.js:
--------------------------------------------------------------------------------
1 | import React, {Fragment, useState, useEffect} from 'react';
2 | import fetch from 'isomorphic-unfetch';
3 | import {withRouter} from 'next/router';
4 |
5 | import Layout from '../components/Layout';
6 | import HackCard from '../components/HackCard';
7 | import PaginationBox from '../components/PaginationBox';
8 | import {PER_PAGE, GLITCH_ENDPOINT} from '../config/global'
9 |
10 | const HackComponent = withRouter(props=>{
11 | return (
12 |
13 | {props.dailyhacks.map(hack => (
14 |
15 |
16 |
17 | ))}
18 |
29 |
30 | )
31 | })
32 |
33 | function DailyHackHome(props){
34 | return(
35 |
36 |
37 |
38 |
39 |
40 |
41 | )
42 | }
43 |
44 | DailyHackHome.getInitialProps = async function(context){
45 | var page_number;
46 | if(context.query.page_number === undefined){
47 | page_number = 1
48 | }else{
49 | page_number = context.query.page_number
50 | }
51 | const url = GLITCH_ENDPOINT + '/issues/' + page_number + '/' + PER_PAGE
52 | const result = await fetch(url)
53 | const data = await result.json()
54 | return {
55 | dailyhacks: data.issues,
56 | page_number: context.query.page_number,
57 | total_issues: data.total_issues,
58 | active_page: page_number
59 | }
60 | }
61 |
62 | export default DailyHackHome
--------------------------------------------------------------------------------
/pages/post.js:
--------------------------------------------------------------------------------
1 | import {withRouter} from 'next/router';
2 | import fetch from 'isomorphic-unfetch';
3 |
4 | import Layout from '../components/Layout';
5 | import HackCard from '../components/HackCard';
6 | import CommentBox from '../components/CommentBox'
7 | import {GLITCH_ENDPOINT} from '../config/global'
8 |
9 | const SinglePost = withRouter(props => {
10 | return(
11 |
12 |
13 |
14 |
15 |
16 |
29 |
30 | )
31 | })
32 |
33 | SinglePost.getInitialProps = async function(context){
34 | const result = await fetch(`${GLITCH_ENDPOINT}/issues/${context.query.number}`)
35 | const issue = await result.json()
36 | return {
37 | single_issue: issue,
38 | slug: `${context.query.slug}-${context.query.number}`
39 | }
40 | }
41 |
42 | export default SinglePost;
--------------------------------------------------------------------------------
/pages/search.js:
--------------------------------------------------------------------------------
1 | import React, {Fragment, useState, useEffect} from 'react';
2 | import fetch from 'isomorphic-unfetch';
3 | import axios from 'axios';
4 |
5 | import Layout from '../components/Layout';
6 | import HackCard from '../components/HackCard';
7 | import PaginationBox from '../components/PaginationBox';
8 | import {withRouter} from 'next/router';
9 | import SearchInput from '../components/SearchInput'
10 | import {GITHUB_ENDPOIINT_LOCAL, PER_PAGE, GITHUB_SEARCH_ENDPOIINT} from '../config/global'
11 |
12 | // function HackComponent(props){
13 | // return (
14 | //
15 | // {props.issues.length > 0 ? props.issues.map(hack => (
16 | //
17 | //
18 | //
19 | // )): 'No Result Found.'}
20 | //
31 | //
32 | // )
33 | // }
34 |
35 | const HackComponent = withRouter(props=>{
36 | return (
37 |
38 | {props.issues.length > 0 ? props.issues.map(hack => (
39 |
40 |
41 |
42 | )): 'No Result Found.'}
43 |
54 |
55 | )
56 | })
57 |
58 | function SearchPage(props){
59 |
60 | const [issues, setIssues] = useState(props.dailyhacks)
61 | const inputQ = props.keywords.split('+').join(' ')
62 | return(
63 |
64 |
65 |
66 |
67 |
82 |
83 |
84 | )
85 | }
86 |
87 | SearchPage.getInitialProps = async function(context){
88 | var keywords = context.query.keywords;
89 | const url = `${GITHUB_SEARCH_ENDPOIINT}?q=${keywords}+repo:mddanishyusuf/dailyhack`
90 | const result = await fetch(url)
91 | const data = await result.json()
92 | return {
93 | dailyhacks: data.items,
94 | keywords
95 | }
96 | }
97 |
98 | export default SearchPage
--------------------------------------------------------------------------------
/pages/sitemap.js:
--------------------------------------------------------------------------------
1 | import React, {Fragment, useState, useEffect} from 'react';
2 | import fetch from 'isomorphic-unfetch';
3 | import {withRouter} from 'next/router';
4 | import getSlug from 'speakingurl'
5 | import Link from 'next/link';
6 | import {DAILYHACK_GITHUB_API} from '../config/global'
7 |
8 | import Layout from '../components/Layout';
9 |
10 | const SiteMapList = withRouter(props=>{
11 | return (
12 |
13 |
Sitemap
14 |
15 | {props.dailyhacks.map(hack => (
16 | {hack.title}
17 | ))}
18 |
19 |
30 |
31 | )
32 | })
33 |
34 | function DailyHackHome(props){
35 | return(
36 |
37 |
38 |
39 |
40 |
41 |
42 | )
43 | }
44 |
45 | DailyHackHome.getInitialProps = async function(context){
46 |
47 | const url = DAILYHACK_GITHUB_API + '/issues/1/100'
48 | const result = await fetch(url)
49 | const data = await result.json()
50 | return {
51 | dailyhacks: data.issues
52 | }
53 | }
54 |
55 | export default DailyHackHome
--------------------------------------------------------------------------------
/pages/tag.js:
--------------------------------------------------------------------------------
1 | import React, {Fragment, useState, useEffect} from 'react';
2 | import fetch from 'isomorphic-unfetch';
3 | import axios from 'axios';
4 | import {withRouter} from 'next/router';
5 |
6 | import Layout from '../components/Layout';
7 | import HackCard from '../components/HackCard';
8 | import PaginationBox from '../components/PaginationBox';
9 | import {GITHUB_ENDPOIINT_LOCAL, PER_PAGE} from '../config/global'
10 |
11 |
12 | const HackComponent = withRouter(props=>{
13 | return (
14 |
15 | {props.issues.map(hack => (
16 |
17 |
18 |
19 | ))}
20 |
31 |
32 | )
33 | })
34 |
35 | function DailyTagPage(props){
36 |
37 | const [issues, setIssues] = useState(props.dailyhacks)
38 | const [loadingCount, setLoadingCount] = useState(true)
39 | const [page, setPage] = useState(2)
40 |
41 | const loadMoreTagIssues = () => {
42 | const url = `${GITHUB_ENDPOIINT_LOCAL}/issues?labels=${props.tag_name}&page=${page}&per_page=${PER_PAGE}`
43 |
44 | axios.get(url).then((res)=>{
45 | if(res.data.length > 0){
46 | setIssues([...issues, ...res.data])
47 | setPage(page+1)
48 | }else{
49 | setLoadingCount(false)
50 | }
51 | })
52 | }
53 |
54 | return(
55 |
56 |
57 | Tag: ${props.tag_name} tricks
58 |
59 |
60 | {loadingCount
61 | ?
Load More
62 | :
That's all. You have any hack then add
here
63 | }
64 |
65 |
80 |
81 |
82 | )
83 | }
84 |
85 | DailyTagPage.getInitialProps = async function(context){
86 | var tag_name = context.query.tag_name;
87 | const url = GITHUB_ENDPOIINT_LOCAL + '/issues?labels='+tag_name+'&page=1&per_page=10'
88 | const result = await fetch(url)
89 | const data = await result.json()
90 | return {
91 | dailyhacks: data,
92 | tag_name
93 | }
94 | }
95 |
96 | export default DailyTagPage
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | const cacheableResponse = require('cacheable-response')
2 | const express = require('express');
3 | const next = require('next');
4 | const axios = require('axios');
5 | const fs = require("fs");
6 |
7 | const port = parseInt(process.env.PORT, 10) || 3000
8 | const dev = process.env.NODE_ENV !== 'production';
9 | const app = next({dev});
10 | const handle = app.getRequestHandler();
11 |
12 | const { DESTINATION, createSitemap } = require("./sitemap");
13 |
14 | const ssrCache = cacheableResponse({
15 | ttl: 1000 * 30 * 60, // 30min
16 | get: async ({ req, res, pagePath, queryParams }) => ({
17 | data: await app.renderToHTML(req, res, pagePath, queryParams)
18 | }),
19 | send: ({ data, res }) => res.send(data)
20 | })
21 |
22 | app
23 | .prepare()
24 | .then(() => {
25 | const server = express();
26 |
27 | // server.get("/sitemap.xml", function(req, res) {
28 | // res.header("Content-Type", "application/xml");
29 | // (async function sendXML() {
30 | // let xmlFile = await createSitemap();
31 | // res.send(xmlFile);
32 | // // fs.writeFileSync(DESTINATION, xmlFile);
33 | // })();
34 | // });
35 |
36 | server.get('/post/:slug', (req, res) => {
37 | const pagePath = '/post'
38 | var slugArray = req.params.slug.split('-')
39 |
40 | const [number] = slugArray.slice(-1)
41 | slugArray.splice(-1,1)
42 | const slug = slugArray.join('-')
43 |
44 | const queryParams = { number, slug }
45 | // app.render(req, res, pagePath, queryParams)
46 | return ssrCache({ req, res, pagePath, queryParams })
47 | })
48 |
49 | server.get('/page/:page_number', (req, res) => {
50 | const pagePath = '/'
51 | const page_number = req.params.page_number
52 | const queryParams = { page_number }
53 | return ssrCache({ req, res, pagePath, queryParams })
54 | // app.render(req, res, pagePath, queryParams)
55 | })
56 |
57 | server.get('/tag/:tag_name', (req, res) => {
58 | const pagePath = '/tag'
59 | const tag_name = req.params.tag_name
60 | const queryParams = { tag_name }
61 | return ssrCache({ req, res, pagePath, queryParams })
62 | // app.render(req, res, pagePath, queryParams)
63 | })
64 |
65 | server.get('/search/:keywords', (req, res) => {
66 | const pagePath = '/search'
67 | const keywords = req.params.keywords
68 | const queryParams = { keywords }
69 | return ssrCache({ req, res, pagePath, queryParams })
70 | // app.render(req, res, pagePath, queryParams)
71 | })
72 |
73 | server.get('/', (req, res) => ssrCache({ req, res, pagePath: '/' }))
74 |
75 | server.get('*', (req, res) => {
76 | return handle(req, res)
77 | })
78 |
79 | server.listen(port, err=> {
80 | if(err) throw err;
81 | console.log(`> Ready on http://localhost:${port}`)
82 | })
83 | })
84 | .catch(ex => {
85 | console.error(ex.stack);
86 | process.exit(1)
87 | })
--------------------------------------------------------------------------------
/sitemap.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const glob = require("glob");
3 | const fs = require("fs");
4 | const axios = require("axios");
5 | const getSlug = require('speakingurl')
6 |
7 | // If you use Dotenv you can include your .env variables uncommenting the following line
8 | // require("dotenv").config();
9 |
10 | // Make sure any symlinks in the project folder are resolved:
11 | // https://github.com/facebookincubator/create-react-app/issues/637
12 | const appDirectory = fs.realpathSync(process.cwd());
13 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
14 | const SITE_ROOT = "https://dailyhack.xyz"
15 |
16 | // API_SOURCE is the endpoint of you api
17 | // Update example.com/api with your endpoint or set the env variable
18 | const API_SOURCE = "https://dailyhack.glitch.me/issues/1/100";
19 |
20 | // DESTINATION is where the real file is exported
21 | // By default is .next/static/sitemap.xml
22 | const DESTINATION =
23 | process.env.DESTINATION ||
24 | path.join(resolveApp("./static"), "sitemap.xml");
25 |
26 |
27 | const createSitemap = () => {
28 | let xml = "";
29 | xml += '';
30 | xml += '';
31 |
32 | return axios
33 | .get(API_SOURCE)
34 | .then(resp => {
35 | let { issues } = resp.data;
36 | issues.forEach((issue, index) => {
37 | xml += "";
38 | xml += `${SITE_ROOT}/post/${[getSlug(issue.title),issue.number].join('-')}`;
39 | xml +=
40 | ` ${issue.updated_at.split('T')[0]} daily 0.8 `;
41 | if (index === issues.length - 1) {
42 | xml += " ";
43 | }
44 | });
45 | return xml;
46 | })
47 | .catch(error => {
48 | console.log(error.message, error.name);
49 | });
50 | };
51 |
52 | module.exports = { DESTINATION, createSitemap };
--------------------------------------------------------------------------------
/static/images/daily-hack-favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mddanishyusuf/dailyhack/1442722d9a10715953d08f67b88e8dd2e43f4f07/static/images/daily-hack-favicon.png
--------------------------------------------------------------------------------
/static/images/daily-hack-image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mddanishyusuf/dailyhack/1442722d9a10715953d08f67b88e8dd2e43f4f07/static/images/daily-hack-image.png
--------------------------------------------------------------------------------
/static/images/daily-hack-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mddanishyusuf/dailyhack/1442722d9a10715953d08f67b88e8dd2e43f4f07/static/images/daily-hack-logo.png
--------------------------------------------------------------------------------
/static/images/header-left-vector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mddanishyusuf/dailyhack/1442722d9a10715953d08f67b88e8dd2e43f4f07/static/images/header-left-vector.png
--------------------------------------------------------------------------------
/static/sitemap.xml:
--------------------------------------------------------------------------------
1 | https://dailyhack.xyz/post/open-links-in-new-tab-safely-62 2019-04-15 daily 0.8 https://dailyhack.xyz/post/tired-of-getting-your-email-spammed-61 2019-04-14 daily 0.8 https://dailyhack.xyz/post/how-to-reload-a-page-using-javascript-60 2019-04-14 daily 0.8 https://dailyhack.xyz/post/macos-toggle-on-character-viewer-to-insert-emoji-to-anywhere-58 2019-04-14 daily 0.8 https://dailyhack.xyz/post/5-keyboard-shortcuts-to-navigate-your-code-faster-57 2019-04-13 daily 0.8 https://dailyhack.xyz/post/use-linux-on-chromeos-55 2019-04-13 daily 0.8 https://dailyhack.xyz/post/geturlparameters-in-javascript-54 2019-04-13 daily 0.8 https://dailyhack.xyz/post/use-the-same-email-to-make-differnt-acc-s-on-one-website-53 2019-04-13 daily 0.8 https://dailyhack.xyz/post/runcat-52 2019-04-13 daily 0.8 https://dailyhack.xyz/post/eject-water-from-your-phone-s-speakers-after-getting-it-wet-51 2019-04-13 daily 0.8 https://dailyhack.xyz/post/handy-macos-terminal-commands-50 2019-04-13 daily 0.8 https://dailyhack.xyz/post/vscode-switch-back-from-settings-ui-to-settings-json-or-vscode-pro-49 2019-04-13 daily 0.8 https://dailyhack.xyz/post/get-day-of-week-48 2019-04-13 daily 0.8 https://dailyhack.xyz/post/macos-mojave-how-to-take-a-screen-capture-47 2019-04-13 daily 0.8 https://dailyhack.xyz/post/finding-a-previous-ip-address-46 2019-04-13 daily 0.8 https://dailyhack.xyz/post/ignoring-a-previously-committed-file-quickly-45 2019-04-13 daily 0.8 https://dailyhack.xyz/post/keyboard-events-live-reference-44 2019-04-13 daily 0.8 https://dailyhack.xyz/post/automatically-update-your-website-footer-43 2019-04-13 daily 0.8 https://dailyhack.xyz/post/slug-text-function-42 2019-04-13 daily 0.8 https://dailyhack.xyz/post/javascript-calculate-age-from-date-small-function-41 2019-04-13 daily 0.8 https://dailyhack.xyz/post/simple-paypal-payment-form-40 2019-04-15 daily 0.8 https://dailyhack.xyz/post/change-the-date-of-a-git-commit-39 2019-04-11 daily 0.8 https://dailyhack.xyz/post/easy-to-remember-local-static-web-server-httpster-38 2019-04-13 daily 0.8 https://dailyhack.xyz/post/check-your-battery-status-and-date-in-your-mac-37 2019-04-13 daily 0.8 https://dailyhack.xyz/post/stores-a-string-to-a-variable-using-scanf-in-c-36 2019-04-13 daily 0.8 https://dailyhack.xyz/post/save-snippets-globally-to-access-in-any-editor-or-any-group-33 2019-04-13 daily 0.8 https://dailyhack.xyz/post/vscode-code-editor-32 2019-04-13 daily 0.8 https://dailyhack.xyz/post/dns-troubleshooting-31 2019-04-13 daily 0.8 https://dailyhack.xyz/post/how-do-display-errors-in-php-30 2019-04-13 daily 0.8 https://dailyhack.xyz/post/my-quick-hack-to-unsubscribe-from-spam-email-in-1-click-29 2019-04-14 daily 0.8 https://dailyhack.xyz/post/a-command-to-give-your-terminal-windows-a-title-28 2019-04-13 daily 0.8 https://dailyhack.xyz/post/hide-desktop-items-on-mac-27 2019-04-13 daily 0.8 https://dailyhack.xyz/post/log-multiple-variables-to-the-js-console-with-their-names-26 2019-04-13 daily 0.8 https://dailyhack.xyz/post/git-push-dev-branch-merge-into-master-push-master-to-origin-go-back-to-dev-25 2019-04-13 daily 0.8 https://dailyhack.xyz/post/screenshot-tool-by-zeit-return-screenshoot-by-url-24 2019-04-13 daily 0.8 https://dailyhack.xyz/post/validate-your-side-project-before-beginning-development-23 2019-04-13 daily 0.8 https://dailyhack.xyz/post/quickly-create-images-for-social-media-and-seo-22 2019-04-13 daily 0.8 https://dailyhack.xyz/post/use-netlify-for-a-free-and-simple-url-shortener-21 2019-04-13 daily 0.8 https://dailyhack.xyz/post/watch-youtube-videos-when-i-do-code-20 2019-04-13 daily 0.8 https://dailyhack.xyz/post/copy-the-ssh-key-id_rsa-pub-directly-from-the-terminal-19 2019-04-13 daily 0.8 https://dailyhack.xyz/post/get-last-typed-command-on-terminal-18 2019-04-13 daily 0.8 https://dailyhack.xyz/post/search-previous-typed-command-on-terminal-17 2019-04-13 daily 0.8 https://dailyhack.xyz/post/vim-search-for-a-term-15 2019-04-13 daily 0.8 https://dailyhack.xyz/post/css-border-awesome-tricks-14 2019-04-13 daily 0.8 https://dailyhack.xyz/post/compress-image-compress-your-image-for-the-web-13 2019-04-13 daily 0.8 https://dailyhack.xyz/post/next-js-application-deploy-on-zeit-7 2019-04-13 daily 0.8 https://dailyhack.xyz/post/alfred-app-6 2019-04-13 daily 0.8 https://dailyhack.xyz/post/taskbook-track-all-my-todos-in-terminal-5 2019-04-13 daily 0.8 https://dailyhack.xyz/post/live-server-use-for-small-development-to-serve-app-in-browser-4 2019-04-13 daily 0.8 https://dailyhack.xyz/post/screen-mailer-record-upload-and-share-link-3 2019-04-13 daily 0.8 https://dailyhack.xyz/post/create-and-share-beautiful-images-of-your-source-code-2 2019-04-13 daily 0.8 https://dailyhack.xyz/post/delete-remote-and-local-branch-in-git-1 2019-04-13 daily 0.8
--------------------------------------------------------------------------------
/static/style.scss:
--------------------------------------------------------------------------------
1 | body{
2 | font-family: 'Quicksand', sans-serif;
3 | }
--------------------------------------------------------------------------------