Skip to content

Commit

Permalink
Merge pull request #10 from asim/api-docs
Browse files Browse the repository at this point in the history
Add generated api docs
  • Loading branch information
asim authored Dec 21, 2024
2 parents e4e4bbb + 5940efa commit 7e9ca5a
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 0 deletions.
128 changes: 128 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package api

import (
"fmt"
)

type Api struct {
Endpoints []*Endpoint
}

type Endpoint struct {
Name string
Path string
Params []*Param
Response []*Value
}

type Param struct {
Name string
Value string
Description string
}

type Value struct {
Type string
Params []*Param
}

var Endpoints = []*Endpoint{
{
Name: "Quran",
Path: "/api/quran",
Params: nil,
Response: []*Value{{Type: "JSON"}},
},
{
Name: "Hadith",
Path: "/api/hadith",
Params: nil,
Response: []*Value{{Type: "JSON"}},
},
{
Name: "Names",
Path: "/api/names",
Params: nil,
Response: []*Value{{Type: "JSON"}},
},
{
Name: "Search",
Path: "/api/search",
Params: []*Param{
{
Name: "q",
Value: "string",
Description: "The question to ask",
},
},
Response: []*Value{{
Type: "JSON",
Params: []*Param{
{Name: "q", Value: "string", Description: "The question asked"},
{Name: "answer", Value: "string", Description: "Answer to the question"},
{Name: "references", Value: "array", Description: "A list of references used"},
},
}},
},
}

func (a *Api) Markdown() string {
var data string

data += "# Endpoints"
data += fmt.Sprintln()
data += fmt.Sprintln("A list of API endpoints")
data += fmt.Sprintln()

for _, endpoint := range a.Endpoints {
data += fmt.Sprintln()
data += "## " + endpoint.Name
data += fmt.Sprintln()
data += fmt.Sprintln("___")
data += fmt.Sprintln("\\")
data += fmt.Sprintln()
data += fmt.Sprintln()
data += fmt.Sprintf("Path: `%s`", endpoint.Path)
data += fmt.Sprintln()

if endpoint.Params != nil {
data += fmt.Sprintln("#### Request")
data += fmt.Sprintln()
data += fmt.Sprintln("Format `JSON`")
data += fmt.Sprintln()
for _, param := range endpoint.Params {
data += fmt.Sprintf("- `%s`: `%s` - %s", param.Name, param.Value, param.Description)
data += fmt.Sprintln()
}
data += fmt.Sprintln()
data += fmt.Sprintln("\\")
data += fmt.Sprintln()
}

if endpoint.Response != nil {
data += fmt.Sprintln("#### Response")
data += fmt.Sprintln()
for _, resp := range endpoint.Response {
data += fmt.Sprintf("Format `%s`", resp.Type)
data += fmt.Sprintln()
for _, param := range resp.Params {
data += fmt.Sprintf("- `%s`: `%s` - %s", param.Name, param.Value, param.Description)
data += fmt.Sprintln()
}
}

data += fmt.Sprintln()
}

data += fmt.Sprintln()
data += fmt.Sprintln()
}

return data
}

func Load() *Api {
a := new(Api)
a.Endpoints = Endpoints
return a
}
116 changes: 116 additions & 0 deletions html/files/api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

<html>
<head>
<title>API | Reminder</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0;}
#head { margin-bottom: 2.5em; }
#head a { margin-right: 10px; color: black; font-weight: bold; text-decoration: none; }
#container { height: 100%; max-width: 1024px; margin: 0 auto; padding: 25px;}
#content { padding-bottom: 100px; }
#content p { padding: 0 0 25px 0; margin: 0; }
@font-face {
font-family: 'arabic';
src: url('/files/arabic.otf') format('opentype');
font-weight: normal;
font-style: normal;
}
.arabic {
font-family: 'arabic';
font-size: 1.5em;
}
.chapter {
margin: 10px;
border: 1px solid grey;
padding: 10px;
display: inline-block;
}
code {
background: whitesmoke;
padding: 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="head">
<a href="/">[Reminder]</a>
<a href="/api">API</a>
<a href="/quran">Quran</a>
<a href="/names">Names</a>
<a href="/hadith">Hadith</a>
<a href="/search">Search</a>
</div>
<div id="content"><h1 id="endpoints">Endpoints</h1>

<p>A list of API endpoints</p>

<h2 id="quran">Quran</h2>

<hr>

<p></p>

<p>Path: <code>/api/quran</code></p>

<h4 id="response">Response</h4>

<p>Format <code>JSON</code></p>

<h2 id="hadith">Hadith</h2>

<hr>

<p></p>

<p>Path: <code>/api/hadith</code></p>

<h4 id="response-1">Response</h4>

<p>Format <code>JSON</code></p>

<h2 id="names">Names</h2>

<hr>

<p></p>

<p>Path: <code>/api/names</code></p>

<h4 id="response-2">Response</h4>

<p>Format <code>JSON</code></p>

<h2 id="search">Search</h2>

<hr>

<p></p>

<p>Path: <code>/api/search</code></p>

<h4 id="request">Request</h4>

<p>Format <code>JSON</code></p>

<ul>
<li><code>q</code>: <code>string</code> - The question to ask</li>
</ul>

<p></p>

<h4 id="response-3">Response</h4>

<p>Format <code>JSON</code></p>

<ul>
<li><code>q</code>: <code>string</code> - The question asked</li>
<li><code>answer</code>: <code>string</code> - Answer to the question</li>
<li><code>references</code>: <code>array</code> - A list of references used</li>
</ul>
</div>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions html/files/hadith.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
border: 1px solid grey;
padding: 10px;
display: inline-block;
}
code {
background: whitesmoke;
padding: 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="head">
<a href="/">[Reminder]</a>
<a href="/api">API</a>
<a href="/quran">Quran</a>
<a href="/names">Names</a>
<a href="/hadith">Hadith</a>
Expand Down
42 changes: 42 additions & 0 deletions html/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,79 @@
border: 1px solid grey;
padding: 10px;
display: inline-block;
}
code {
background: whitesmoke;
padding: 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="head">
<a href="/">[Reminder]</a>
<a href="/api">API</a>
<a href="/quran">Quran</a>
<a href="/names">Names</a>
<a href="/hadith">Hadith</a>
<a href="/search">Search</a>
</div>
<div id="content"><h1 id="what-is-the-reminder">What is the Reminder?</h1>

<p>The Reminder refers to divine revelations, particularly the Quran, which serves as guidance, a warning, and a source of mercy for believers. It is meant to encourage mindfulness of Allah and righteousness among people.</p>

<h1 id="what-is-the-quran">What is the Quran?</h1>

<p>The Quran is the holy book of Islam, believed to be the word of Allah (God) as revealed to the Prophet Muhammad through the angel Gabriel. It serves as a guide for personal conduct, law, and spirituality for Muslims and is recited in Arabic. The Quran consists of verses (ayahs) organized into chapters (surahs) and covers various aspects of life, morality, guidance, and worship.</p>

<h1 id="what-is-the-hadith">What is the Hadith?</h1>

<p>Hadith refers to the recorded sayings, actions, and approvals of the Prophet Muhammad. These narrations serve as a significant source of guidance for Muslims, alongside the Quran, addressing various aspects of life, ethics, law, and spirituality.</p>

<h1 id="who-is-allah">Who is Allah?</h1>

<p>Allah is the one true God, the Creator of all things, and the Almighty. He is all-knowing, most merciful, and is recognized as the Sustainer of the heavens and the earth. Allah is unique, having no partners or offspring, and is deserving of worship alone. He is described with many beautiful names and attributes, reflecting His majesty and perfection.</p>

<h1 id="who-is-the-prophet-muhammad">Who is the prophet Muhammad</h1>

<p>Prophet Muhammad is considered the last prophet in Islam, sent by Allah as a messenger to guide humanity. He is known for conveying the teachings of Islam and the Quran, which emphasizes monotheism, moral conduct, and compassion. Born in Mecca around 570 CE, he led a life of integrity and became a key figure in the establishment of the Islamic faith. His character and teachings continue to influence millions of people around the world today.</p>

<h1 id="why-do-we-worship-allah">Why do we &lsquo;worship&rsquo; Allah?</h1>

<p>We worship Allah because He is the Creator of all things, worthy of reverence and devotion. Worshiping Allah provides a means of expressing gratitude, seeking guidance, and establishing a relationship with Him. It acknowledges His unique attributes as the One who sustains and controls everything, fostering a sense of purpose and connection to the divine.</p>

<h1 id="how-do-we-worship-allah">How do we &lsquo;worship&rsquo; Allah?</h1>

<p>Worshiping Allah involves sincere devotion, which includes prayer (Salah), recitation of the Quran, giving charity (Zakat), fasting during Ramadan, and performing good deeds. It also entails acknowledging His oneness, praising Him, and following His guidance in daily life. Ultimately, it is about establishing a deep, personal connection with Allah through acts of worship and obedience.</p>

<h1 id="what-happens-when-we-die">What happens when we die?</h1>

<p>When we die, our souls are taken by the Angel of Death, and we are returned to Allah for judgment. Every soul will taste death, and after that, there will be a resurrection on the Day of Judgment where everyone will be held accountable for their deeds. The outcome will determine whether one is rewarded with paradise or punished in hell.</p>

<h1 id="how-do-i-remember-allah">How do I remember Allah?</h1>

<p>You can remember Allah by engaging in regular prayers (Salah), reciting the Quran, invoking Allah&rsquo;s names, reflecting on His creation, and being mindful of His favors. Additionally, maintaining a consistent practice of dhikr (remembrance) and gratitude can deepen your connection with Him.</p>

<h1 id="how-do-i-become-muslim">How do I become Muslim?</h1>

<p>To become a Muslim, you need to declare the Shahada, which is the testimony of faith. This involves reciting the following declaration with conviction:</p>

<p>&ldquo;أشهد أن لا إله إلا الله وأشهد أن محمدًا رسول الله&rdquo;
(&ldquo;Ashhadu an la ilaha illallah, wa ashhadu anna Muhammadur rasulullah&rdquo;)
Translation: &ldquo;I bear witness that there is no god but Allah, and Muhammad is His messenger.&rdquo;</p>

<p>After making this declaration, you are considered a Muslim. It is also recommended to learn about the basic beliefs and practices of Islam, including the Five Pillars:</p>

<ol>
<li>Shahada (Faith)</li>
<li>Salah (Prayer)</li>
<li>Zakat (Charity)</li>
<li>Sawm (Fasting during Ramadan)</li>
<li>Hajj (Pilgrimage to Mecca, if possible).</li>
</ol>

<p>Seeking knowledge and guidance from a local Islamic community can help you in your journey.</p>
</div>
</div>
</body>
Expand Down
6 changes: 6 additions & 0 deletions html/files/names.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
border: 1px solid grey;
padding: 10px;
display: inline-block;
}
code {
background: whitesmoke;
padding: 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="head">
<a href="/">[Reminder]</a>
<a href="/api">API</a>
<a href="/quran">Quran</a>
<a href="/names">Names</a>
<a href="/hadith">Hadith</a>
Expand Down
6 changes: 6 additions & 0 deletions html/files/quran.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
border: 1px solid grey;
padding: 10px;
display: inline-block;
}
code {
background: whitesmoke;
padding: 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="head">
<a href="/">[Reminder]</a>
<a href="/api">API</a>
<a href="/quran">Quran</a>
<a href="/names">Names</a>
<a href="/hadith">Hadith</a>
Expand Down
Loading

0 comments on commit 7e9ca5a

Please sign in to comment.