First commit

This commit is contained in:
0x1eef 2024-10-16 23:57:13 -03:00
commit e9b6586a3a
898 changed files with 47123 additions and 0 deletions

12
.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
node_modules/
dist/
/.gems/
/build/
/tmp/
/rake/tasks/deploy.rake
/packages/**/*.js
/submodules/
/crash.log
/*.core/
/nanoc.yaml
/source

19
Gemfile Normal file
View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
source "https://rubygems.org"
##
# nanoc
gem "nanoc", "~> 4.12"
gem "nanoc-webpack.rb", "~> 0.10"
gem "nanoc-tidy.rb", "~> 0.8.4"
##
# dev
gem "server.rb"
gem "ryo.rb"
gem "standard", "~> 1.24"
gem "paint", "~> 2.3"
gem "listen", "~> 3.0"
gem "test-cmd.rb"
gem "rexml", "~> 3.3.3"
gem "rake", "~> 13.2"

163
Gemfile.lock Normal file
View file

@ -0,0 +1,163 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
coderay (1.1.3)
colored (1.2)
concurrent-ruby (1.3.4)
cri (2.15.12)
ddmetrics (1.1.0)
ddplugin (1.0.3)
diff-lcs (1.5.1)
ffi (1.17.0)
immutable-ruby (0.2.0)
concurrent-ruby (~> 1.1)
sorted_set (~> 1.0)
json (2.7.2)
json_schema (0.21.0)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
memo_wise (1.9.0)
method_source (1.1.0)
nanoc (4.13.0)
addressable (~> 2.5)
colored (~> 1.2)
nanoc-checking (~> 1.0, >= 1.0.2)
nanoc-cli (= 4.13.0)
nanoc-core (= 4.13.0)
nanoc-deploying (~> 1.0)
parallel (~> 1.12)
tty-command (~> 0.8)
tty-which (~> 0.4)
nanoc-checking (1.0.5)
nanoc-cli (~> 4.12, >= 4.12.5)
nanoc-core (~> 4.12, >= 4.12.5)
nanoc-cli (4.13.0)
cri (~> 2.15)
diff-lcs (~> 1.3)
nanoc-core (= 4.13.0)
pry
zeitwerk (~> 2.1)
nanoc-core (4.13.0)
base64 (~> 0.2)
concurrent-ruby (~> 1.1)
ddmetrics (~> 1.0)
ddplugin (~> 1.0)
immutable-ruby (~> 0.1)
json_schema (~> 0.19)
memo_wise (~> 1.5)
psych (>= 4.0, < 6.0)
slow_enumerator_tools (~> 1.0)
tty-platform (~> 0.2)
zeitwerk (~> 2.1)
nanoc-deploying (1.0.2)
nanoc-checking (~> 1.0)
nanoc-cli (~> 4.11, >= 4.11.15)
nanoc-core (~> 4.11, >= 4.11.15)
nanoc-tidy.rb (0.8.4)
ryo.rb (~> 0.5)
test-cmd.rb (~> 0.12.4)
nanoc-webpack.rb (0.10.6)
ryo.rb (~> 0.5)
test-cmd.rb (~> 0.12.4)
nio4r (2.7.3)
paint (2.3.0)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
pastel (0.8.0)
tty-color (~> 0.5)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.1.2)
stringio
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.7)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbtree (0.4.6)
regexp_parser (2.9.2)
rexml (3.3.6)
strscan
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
ryo.rb (0.5.6)
server.rb (0.4.0)
puma (~> 6.3)
rack (~> 3.0)
set (1.1.0)
slow_enumerator_tools (1.1.0)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
standard (1.40.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.65.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
stringio (3.1.1)
strscan (3.1.0)
test-cmd.rb (0.12.4)
tty-color (0.6.0)
tty-command (0.10.1)
pastel (~> 0.8)
tty-platform (0.3.0)
tty-which (0.5.0)
unicode-display_width (2.5.0)
zeitwerk (2.6.17)
PLATFORMS
amd64-freebsd-14
ruby
DEPENDENCIES
listen (~> 3.0)
nanoc (~> 4.12)
nanoc-tidy.rb (~> 0.8.4)
nanoc-webpack.rb (~> 0.10)
paint (~> 2.3)
rake (~> 13.2)
rexml (~> 3.3.3)
ryo.rb
server.rb
standard (~> 1.24)
test-cmd.rb
BUNDLED WITH
2.5.9

107
README.md Normal file
View file

@ -0,0 +1,107 @@
## About
This repository contains a port of the
[al-quran.reflectslight.io](https://al-quran.reflectslight.io)
website for the mobile operating system
[KaiOS](https://www.kaiostech.com/).
The project is still in the early stages of development.
## Requirements
The following languages and tools have to be
installed to build the website from source:
* Ruby 3.2 (or later)
* NodeJS v18.15 (or later)
* [tidy-html5](https://github.com/htacg/tidy-html5)
## Development
# Clone repository
git clone https://github.com/ReflectsLight/al-quran.reflectslight.io
cd al-quran.reflectslight.io
# Setup build environment
bin/setup
# List all tasks
bundle exec rake -T
# Build website (dev build)
bundle exec rake nanoc:build
# Build website (production build)
bundle exec rake nanoc:build[production]
# Start web server
bundle exec rake server
## Configuration
* **server.base_url** <br>
If you plan to host the website on
your own domain you should update
[nanoc.yaml](nanoc.yaml.sample)
first. In certain places
links will reference
https://al-quran.reflectslight.io
instead of using a relative path.
For example
[/src/sitemap.xml.erb](/src/sitemap.xml.erb)
is one such place. Those links can be updated
to your own domain by changing the `server.base_url`
field in
[nanoc.yaml](nanoc.yaml.sample)
before running `bundle exec rake nanoc:build`.
* **audio.base_url** <br>
`audio.base_url` controls what web server serves
audio content.
[The default](https://al-quran.reflectslight.io/audio/rifai)
works out of the box. The URL for an audio file is
resolved by joining `audio.base_url` and
`/<surahid>/<ayahid>.mp3`. The `audio.base_url` option
makes it relatively easy to change the reciter
at build time, before deploying the website.
The https://al-quran.reflectslight.io web server
provides the following recitations:
- Mishari bin Rashed Alafasy <br>
https://al-quran.reflectslight.io/audio/alafasy
- Ahmad bin Ali Al-Ajmi <br>
https://al-quran.reflectslight.io/audio/alajmi
- Sahl Yassin <br>
https://al-quran.reflectslight.io/audio/yassin
- Hani ar-Rifai <br>
https://al-quran.reflectslight.io/audio/rifai
**Note**<br>
Due to their overall size the audio files are the only
files **not** kept in this repository. The audio files
are hosted by https://al-quran.reflectslight.io instead.
## Thanks
الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ
* Thanks to the graphic artists:
- [RefreshIcon](/src/js/components/Icon.tsx)
by
[Muhammad Haq](https://freeicons.io/profile/823)
* Thanks to the translators:
- English (The Clear Quran) by Dr. Mustafa Khattab
- Farsi by Hussain Ansarian
* Thanks to the reciters:
- Mishari bin Rashed Alafasy
- Ahmad bin Ali Al-Ajmi
- Sahl Yassin
- Hani ar-Rifai
* Thanks to [@farooqkz](https://github.com/farooqkz) who introduced me to
[KaiOS](https://www.kaiostech.com/),
and inspired me to start work on this project
## License
The "source code" is released under the terms of the GPL <br>
See [LICENSE](./share/al-quran.reflectslight.io/LICENSE) for details

22
Rakefile.rb Normal file
View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
require "bundler/setup"
require "nanoc"
require "ryo"
require "ryo/yaml"
require "ryo/json"
require_relative "nanoc/lib/utils"
include Utils
begin
load "rake/tasks/deploy.rake"
rescue LoadError => ex
warn "[warn] #{ex.class}: #{ex.message}"
end
load "rake/tasks/format.rake"
load "rake/tasks/nanoc.rake"
load "rake/tasks/t.rake"
load "rake/tasks/ci.rake"
load "rake/tasks/server.rake"
task default: "nanoc:build"

58
Rules Normal file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Requires
require "ryo"
require "ryo/json"
require "ryo/yaml"
require "nanoc-webpack"
require "nanoc-tidy"
##
# Extensions
[Nanoc::RuleDSL::CompilationRuleContext, Nanoc::RuleDSL::CompilerDSL].each { _1.prepend(Utils) }
Nanoc::RuleDSL::CompilationRuleContext.prepend(Nanoc::Extension::AnonymousFilter)
Nanoc::RuleDSL::CompilerDSL.prepend(Nanoc::Extension::RequireRules)
##
# Locals
locales = %w[ar fa en]
name_by_id = Ryo.from_json(path: File.join(dirs.content, "json", "nameById.json"))
tdata = Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
surahs = Ryo.from_json(path: File.join(dirs.content, "json", "surahs.json"))
tidy = `which tidy || which tidy5`.chomp
buildenv = ENV["buildenv"] || "development"
etcdir = File.join(__dir__, "etc")
globals = {buildenv:, locales:, tidy:, tdata:, surahs:, name_by_id:}
##
# Filters
Nanoc::Tidy
.default_argv
.replace([*Nanoc::Tidy.default_argv, "-upper"].uniq)
##
# Rules
passthrough "/json/durations/*.json"
require_rules "nanoc/rules/assets"
require_rules "nanoc/rules/redirect", globals
require_rules "nanoc/rules/random", globals
require_rules "nanoc/rules/surah-stream", globals
require_rules "nanoc/rules/surah-index", globals
compile "/js/main/vendor.ts" do
filter :webpack,
argv: %w[--config etc/webpack.vendor.js]
write("/js/main/vendor.js")
end
compile("/manifest.webapp") do
write("/manifest.webapp")
end
compile("/**/*") { write(nil) }
layout("**/*", :erb)
postprocess do
# Remove build artifacts
system "rm -rf #{nanoc.output_dir}/json/"
end

59
bin/setup Executable file
View file

@ -0,0 +1,59 @@
#!/bin/sh
set -e
##
# functions
printok()
{
echo "ok: ${1}" > /dev/stdout
}
printerr()
{
echo "error: ${1}" > /dev/stderr
}
require_dependency()
{
local cmd
for i in $(seq 1 $#); do
eval "cmd=\$${i}"
if which "${cmd}" > /dev/null 2>&1; then
printok "${cmd} found"
else
printerr "${cmd} is required but was not found on \$PATH"
exit 1
fi
done
}
##
# main
require_dependency git bundle npm
git submodule update -f --init --recursive
printok "submodules checked out"
bundle install
printok "ruby dependencies installed"
npm i
printok "nodejs dependencies installed"
if [ ! -e "nanoc.yaml" ]; then
cp nanoc.yaml.sample nanoc.yaml
printok "nanoc.yaml.sample -> nanoc.yaml"
fi
found=0
for t in tidy tidy5; do
if which ${t} > /dev/null 2>&1; then
found=1
break
fi
done
if [ "${found}" = "1" ]; then
printok "tidy-html5 found"
else
printerr "tidy-html5 is required but was not found on \$PATH"
fi

12
etc/eslint.config.mjs Normal file
View file

@ -0,0 +1,12 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-plugin-prettier/recommended';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
prettier,
{
rules: {'@typescript-eslint/no-require-imports': 0},
}
)

49
etc/rubocop.yml Normal file
View file

@ -0,0 +1,49 @@
##
# Defaults
AllCops:
TargetRubyVersion: 3.2
Exclude:
- submodules/**/*
Include:
- Rakefile.rb
- rake/tasks/*.rake
- nanoc/rules/*.rules
- nanoc/rules/**/**/*.rules
- nanoc/lib/*.rb
- nanoc/lib/**/*.rb
- nanoc/lib/**/**.rb
##
# Defaults: standard-rb
require:
- standard
inherit_gem:
standard: config/base.yml
##
# Enabled
Style/FrozenStringLiteralComment:
Enabled: true
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
##
# Disabled
Style/MixinUsage:
Exclude:
- Rakefile.rb
Style/SuperArguments:
Exclude:
- nanoc/lib/nanoc/extension/anonymous_filter.rb
Layout/MultilineMethodCallIndentation:
Enabled: false
Layout/ArgumentAlignment:
Enabled: false
Layout/ArrayAlignment:
Enabled: false
Layout/ExtraSpacing:
Enabled: false
Style/TrivialAccessors:
Enabled: false
Style/PercentLiteralDelimiters:
Enabled: false

20
etc/tsconfig.json Normal file
View file

@ -0,0 +1,20 @@
{
"include": ["../src/**/*.ts", "../src/**/*.tsx"],
"exclude": ["../node_modules"],
"compilerOptions": {
"strict": true,
"module": "commonjs",
"target": "ES5",
"noImplicitAny": true,
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "react",
"lib": [ "ES2020", "DOM" ],
"baseUrl": "../src/",
"paths": {
"~/*": ["./js/*"],
"@json/*": ["./json/*"]
},
}
}

49
etc/webpack.common.js Normal file
View file

@ -0,0 +1,49 @@
const path = require("path");
module.exports = (env, argv) => {
return {
devtool: "source-map",
resolve: {
modules: [path.resolve(__dirname, "..", "node_modules")],
alias: {
"@css": path.resolve(__dirname, "..", "src", "css"),
"@json": path.resolve(__dirname, "..", "src", "json"),
"~": path.resolve(__dirname, "..", "src", "js"),
},
extensions: [".js", ".ts", ".tsx", ".json", ".css", ".scss"],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
['@babel/preset-env', {
targets: {
esmodules: false,
browsers: ['KaiOS >= 2.5', 'Firefox >= 48'],
},
useBuiltIns: 'entry',
corejs: 3,
}],
'@babel/preset-typescript',
'@babel/preset-react'
],
},
},
{
test: /\.(scss|css)$/i,
exclude: /node_modules/,
use: [
"style-loader",
"css-loader",
"sass-loader",
]
}
],
},
plugins: [],
optimization: {}
}
};

View file

@ -0,0 +1,8 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = (env, argv) => {
return merge(
common(env, argv),
{ mode: "development" }
)
}

12
etc/webpack.production.js Normal file
View file

@ -0,0 +1,12 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = (env, argv) => {
return merge(
common(env, argv),
{
mode: "production",
devtool: false,
optimization: { minimize: true },
}
)
}

14
etc/webpack.vendor.js Normal file
View file

@ -0,0 +1,14 @@
const path = require('path');
const common = require('./webpack.common.js');
const { merge } = require('webpack-merge');
module.exports = (env, argv) => {
return merge(
common(env, argv),
{
output: { library: { type: 'umd' } },
resolve: { extensions: ['.ts', '.tsx'] },
optimization: { minimize: true }
}
)
}

32
nanoc.yaml.sample Normal file
View file

@ -0,0 +1,32 @@
# A list of file extensions that Nanoc will consider to be textual rather than
# binary. If an item with an extension not in this list is found, the file
# will be considered as binary.
text_extensions: [
'adoc', 'asciidoc', 'atom', 'coffee', 'css', 'erb', 'haml',
'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown',
'md', 'ms', 'mustache', 'php', 'rb', 'rdoc', 'sass', 'scss',
'slim', 'tex', 'txt', 'xhtml', 'xml', 'ts', 'tsx', 'json'
]
prune:
auto_prune: true
lib_dirs: ['nanoc/lib']
output_dir: build/al-quran/
data_sources:
- type: filesystem
encoding: UTF-8
content_dir: src/
layouts_dir: src/layouts
audio:
base_url: https://audio.al-quran.reflectslight.io/rifai
server:
base_url: https://al-quran.reflectslight.io
unix:
path:
tcp:
host: 127.0.0.1
port: 7777

View file

@ -0,0 +1,42 @@
# frozen_string_literal: true
module Nanoc::Extension
##
# The AnonymousFilter extension adds support for Proc-based
# filters. See the Rules file to learn how this module is
# added to nanoc
module AnonymousFilter
require "securerandom"
##
# @example
# compile "/sitemap.xml.erb" do
# filter(:erb)
# filter Proc.new { _1.each_line.reject { |s| s.strip.empty? }.join }
# write("/sitemap.xml")
# end
# @param [Proc, Symbol] fn
# Symbol, or Proc for an anonymous filter
# @param [Hash] options
# Filter options
# @return [void]
def filter(fn, options = {})
if Proc === fn
id = anonymous_id
Nanoc::Filter.define(id) { fn.call(_1, _2) }
super(id, options)
else
super(fn, options)
end
end
private
def anonymous_id
[
"__nanoc",
item.identifier.to_s.gsub(%r{[./\\]}, "_")[/[A-Za-z0-9_]+/],
SecureRandom.alphanumeric
].join("_").to_sym
end
end
end

View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
module Nanoc::Extension
##
# The RequireRules extension adds a method that can help
# break up the Rules file into multiple separate files.
# See the Rules file to learn how this module is added
# to nanoc
module RequireRules
##
# @example
# require_rules "nanoc/rules/assets"
# require_rules "nanoc/rules/index", {locales: ["en", "ar", "fa"]}
# @param [String] path
# @param [Hash] locals
# @param [Binding] target
# @return [void]
def require_rules(path, locals = {}, target = binding)
locals.each { target.local_variable_set(_1, _2) }
path = File.join(Dir.getwd, path)
target.eval(
if File.readable?(path)
File.read(path)
elsif File.readable?("#{path}.rb")
File.read("#{path}.rb")
elsif File.readable?("#{path}.rules")
File.read("#{path}.rules")
else
raise LoadError, "#{path} is not readable"
end
)
end
end
end

100
nanoc/lib/utils.rb Normal file
View file

@ -0,0 +1,100 @@
# frozen_string_literal: true
##
# The {Utils Utils} module provides methods that are
# available at build time. ERB templates, the Rules file
# and Rakefile.rb all have access to the methods of this
# module
module Utils
require "test-cmd"
require_relative "utils/t"
require_relative "utils/inline"
require_relative "utils/erb"
##
# Generic error
Error = Class.new(RuntimeError) unless defined?(Error)
##
# @return [Ryo::Object]
# Returns common directory paths as a Ryo object
def dirs
@dirs ||= Ryo(
root:,
build: File.join(root, nanoc.output_dir),
content: File.join(root, nanoc.data_sources[0].content_dir)
)
end
##
# @return [Ryo::Object]
# Returns the contents of nanoc.yaml as a Ryo object
def nanoc
@nanoc ||= Ryo.from_yaml(path: File.join(root, "nanoc.yaml"))
end
##
# @return [String]
# Returns an absolute path to the root directory of the website
def root
@root ||= File.realpath(File.join(__dir__, "..", "..", "."))
end
##
# @return [String]
# Returns the website version
def version
@version ||= begin
path = File.join(dirs.root, "share", "al-quran.reflectslight.io", "VERSION")
File.read(path).gsub(/[^\d.]/, "")
end
end
##
# @raise [Utils::Error]
# When git fails or is unavailable
# @return [String]
# Returns the most recent git commit hash
def commit
@commit ||= begin
hash = nil
cmd("git", "rev-parse", "HEAD")
.success { hash = _1.stdout.strip }
.failure { error!("git exited unsuccessfully in method Utils#commit") }
hash
end
end
##
# The URL for an audio file is resolved
# by joining `nanoc.audio.base_url` and
# `/<surahid>/<ayahid>.mp3`.
#
# @return [String]
# Returns the base url for audio requests.
# The default (https://al-quran.reflectslight.io/audio/alafasy)
# works out of the box.
def audio_base_url
nanoc.audio.base_url
end
##
# @return [String]
# Returns the base URL for use with opengraph,
# <link> tags, /sitemap.xml, etc. The default is
# https://al-quran.reflectslight.io.
def base_url
nanoc.server.base_url
end
include T
include Inline
include ERB
private
def error!(m)
raise Error, m, []
end
end
use_helper(Utils) if respond_to?(:use_helper)

19
nanoc/lib/utils/erb.rb Normal file
View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
##
# The {Utils::ERB Utils::ERB} module provides a method
# that can render an ERB template
module Utils::ERB
##
# @param [String] file
# The path to an ERB template
# @param [Hash] local_assigns
# Template variables
# @return [String]
def erb(file, local_assigns = {})
erb = File.binread File.join(dirs.content, "html", file)
ctx = binding
local_assigns.each { ctx.local_variable_set(_1, _2) }
::ERB.new(erb).result(ctx)
end
end

18
nanoc/lib/utils/inline.rb Normal file
View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
module Utils::Inline
def inline_css(path)
class_name = File.basename(path, File.extname(path))
%|<style class="css #{class_name}">| \
"#{items[path].compiled_content}" \
"</style>"
end
def inline_json(path, context:, class_name: File.basename(path, File.extname(path)))
ctx = Ryo.table_of(context).map { [_1.to_sym, _2] }.to_h
path = format(path, ctx)
%|<script type='application/json' class="json #{class_name}">| \
"#{items[path].compiled_content}" \
"</script>"
end
end

26
nanoc/lib/utils/t.rb Normal file
View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
##
# The {Utils::T Utils::T} module provides a method that
# can render user-facing text strings in different
# locales / languages
module Utils::T
##
# @param [String] locale
# Locale (eg "en")
# @param [String] key
# Translation key (eg "TheNobleQuran")
# @param [Hash] local_assigns
# Template variables
# @return [String]
def t(locale, key, local_assigns = {})
str = [locale, *key.split(".")].inject(tdata) { _1[_2] }
format(str, local_assigns)
end
private
def tdata
@tdata ||= Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
end
end

19
nanoc/rules/assets.rules Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Contains rules for images, fonts, etc
##
# images
compile "/images/*.svg" do
write(item.identifier.to_s)
end
compile "/images/*.png" do
write(item.identifier.to_s)
end
compile "/favicon.ico" do
write(item.identifier.to_s)
end

22
nanoc/rules/random.rules Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Contains rules for a redirect from /<locale>/random/ to a
# random surah (eg /en/random/ -> /en/al-kahf/)
locales.each do |locale|
compile "/html/main/random.html.erb", rep: "random/#{locale}" do
context = Ryo.from({dir: tdata[locale].dir, locale:, locales:})
filter(:erb, locals: {context:})
filter(:tidy, exe: tidy)
write("/#{locale}/random/index.html")
end
end
compile "/js/main/random.ts" do
filter :webpack,
argv: ["--config", "etc/webpack.#{buildenv}.js"],
depend_on: ["/js/lib/"]
write("/js/main/random.js")
end

View file

@ -0,0 +1,19 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Contains rules for a redirect from the root path
# to the surah index for a given locale (eg / -> /en/)
compile "/html/main/redirect.html.erb" do
filter(:erb, locals: {context: Ryo(locale: "en"), locales:})
filter(:tidy, exe: tidy)
write("/index.html")
end
compile "/js/main/redirect.ts" do
filter :webpack,
argv: ["--config", "etc/webpack.#{buildenv}.js"],
depend_on: ["/js/lib/"]
write("/js/main/redirect.js")
end

View file

@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Contains rules for the surah index available
# at /<locale>/
locales.each do |locale|
compile "/html/main/surah-index.html.erb", rep: "/#{locale}/surah/index" do
context = Ryo.from(dir: tdata[locale].dir, locale:, locales:)
filter(:erb, {locals: {context:}})
filter(:tidy, exe: tidy)
write "/#{locale}/index.html"
end
end
compile "/js/main/surah-index.tsx" do
filter :webpack,
argv: ["--config", "etc/webpack.#{buildenv}.js"],
depend_on: [
"/js/components",
"/js/lib",
"/js/hooks",
"/css"
]
write "/js/main/surah-index.js"
end

View file

@ -0,0 +1,40 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Contains rules for the the surah stream available
# at /<locale>/<name>/, /<locale>/<id>/
compile "/json/*/*/{surah,info}.json" do
write(item.identifier.to_s)
end
Ryo.each(name_by_id) do |id, slug|
write_file = ->(locale, pathname:) do
surah = surahs[locale][id.to_i - 1]
context = Ryo.from(locale:, surah_id: surah.id, locales:, surah:, dir: tdata[locale].dir)
filter(:erb, locals: {context:})
filter(:tidy, exe: tidy)
write "/#{locale}/#{pathname}/index.html"
end
locales.each do |locale|
compile "/html/main/surah-stream.html.erb", rep: "/#{locale}/#{slug}/index.html" do
instance_exec(locale, pathname: slug, &write_file)
end
compile "/html/main/surah-stream.html.erb", rep: "/#{locale}/#{id}/index.html" do
instance_exec(locale, pathname: id, &write_file)
end
end
end
compile "/js/main/surah-stream.tsx" do
filter :webpack,
argv: ["--config", "etc/webpack.#{buildenv}.js"],
depend_on: [
"/js/components",
"/js/lib",
"/js/hooks",
"/css"
]
write "/js/main/surah-stream.js"
end

6388
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

40
package.json Normal file
View file

@ -0,0 +1,40 @@
{
"name": "al-quran.reflectslight.io",
"workspaces": [
"./packages/typescript/*"
],
"scripts": {
"tsc": "npx tsc --noEmit -p etc/tsconfig.json",
"eslint": "npx eslint --config etc/eslint.config.mjs src/js/",
"eslint:apply": "npx eslint --config etc/eslint.config.mjs --fix src/js/"
},
"dependencies": {
"preact": "^10.23.2",
"@preact/compat": "^17.1.2",
"classnames": "^2.3"
},
"devDependencies": {
"@babel/preset-env": "^7.25.4",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@types/css-font-loading-module": "^0.0.13",
"@types/react": "^18.0",
"@types/react-dom": "^18.0",
"babel-loader": "^9.1.3",
"core-js": "^3.38.1",
"css-loader": "^7.1",
"eslint": "^9.8",
"eslint-config-prettier": "^9.1",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3",
"sass": "^1.77",
"sass-loader": "^16.0",
"style-loader": "^4.0",
"typescript": "^5.5",
"typescript-eslint": "^8.2",
"url": "^0.11",
"webpack": "^5.93",
"webpack-cli": "^5.1",
"webpack-merge": "^6.0"
}
}

0
packages/ruby/.gitkeep Normal file
View file

View file

@ -0,0 +1,21 @@
{
"name": "Quran",
"version": "0.1.0",
"description": "The Noble Quran: a programmer's interface",
"main": "dist/index.js",
"types": ["dist/index.d.ts"],
"scripts": {
"build": "npm exec tsc",
"prepare": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ReflectsLight/al-quran.reflectslight.io.git"
},
"author": "0x1eef",
"license": "0BSDL",
"devDependencies": {
"@types/node": "^22.0",
"typescript": "^5.5"
}
}

View file

@ -0,0 +1,95 @@
/**
* Types
*/
type TAyat = Ayah[];
type TLocale = {
readonly name: string,
readonly displayName: string,
readonly direction: "rtl" | "ltr"
};
type TQuran = {
readonly locale: TLocale;
readonly surahs: Surah[];
}
type TSurah = {
readonly id: number;
readonly name: string;
readonly urlName: string;
readonly translitName: string;
readonly numberOfAyah: number;
readonly translatedBy: string | null;
};
type TAyah = {
readonly id: number;
readonly body: string;
}
/**
* Classes
*/
class Quran {
readonly locale: TLocale;
readonly surahs: Surah[];
/**
* @returns {Array} The available locales
*/
static get locales(): TLocale[] {
return [
{"name": "en", "displayName": "English", "direction": "ltr"},
{"name": "ar", "displayName": "العربية", "direction": "rtl"},
{"name": "fa", "displayName": "فارسی", "direction": "rtl"}
];
}
constructor(self: TQuran) {
this.locale = self.locale;
this.surahs = self.surahs;
}
}
class Surah {
readonly id: number;
readonly name: string;
readonly urlName: string;
readonly translitName: string;
readonly numberOfAyah: number;
readonly ayat: TAyat;
readonly translatedBy: string | null;
constructor(self: TSurah) {
this.id = self.id;
this.name = self.name;
this.urlName = self.urlName;
this.translitName = self.translitName;
this.numberOfAyah = self.numberOfAyah;
this.ayat = [];
this.translatedBy = self.translatedBy;
return this;
}
}
class Ayah {
readonly id: number;
readonly body: string;
ms: number;
constructor(self: TAyah) {
this.id = self.id;
this.body = self.body;
this.ms = 0;
}
}
/**
* Exports
*/
export {
Quran, Surah, Ayah,
TQuran, TSurah, TAyah,
TAyat, TLocale
};

View file

@ -0,0 +1,15 @@
{
"compilerOptions": {
"strict": true,
"module": "ESNEXT",
"target": "ES2020",
"esModuleInterop": true,
"moduleResolution": "node",
"baseUrl": "src/",
"paths": { "*": ["*"] },
"outDir": "dist",
"declaration": true,
}
}

22
rake/tasks/ci.rake Normal file
View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
namespace :ci do
task :rubocop do
sh "bundle exec rubocop -c etc/rubocop.yml"
end
task :eslint do
sh "npm run eslint"
end
task :tsc do
sh "npm run tsc"
end
task :env do
ENV["buildenv"] = "production"
end
end
desc "Run CI tasks"
task ci: %i[ci:env ci:rubocop ci:eslint ci:tsc nanoc:clean nanoc:build]

26
rake/tasks/format.rake Normal file
View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
namespace :format do
desc "Run rubocop (Ruby)"
task :rubocop do
sh "bundle exec rubocop --config etc/rubocop.yml"
end
desc "Apply rubocop (Ruby)"
task :"rubocop:apply" do
sh "bundle exec rubocop -A --config etc/rubocop.yml"
end
desc "Run eslint (TypeScript)"
task :eslint do
sh "npm run eslint"
end
desc "Run eslint (TypeScript)"
task :"eslint:apply" do
sh "npm run eslint:apply"
end
end
desc "Run all formats"
task format: ["format:rubocop", "format:eslint"]

34
rake/tasks/nanoc.rake Normal file
View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
namespace :nanoc do
desc "Clean directories"
task :clean do
Dir.chdir(dirs.root) do
sh "rm -rf node_modules/.cache/"
sh "rm -rf #{nanoc.output_dir}/*"
sh "rm -rf tmp/"
end
end
desc "Produce the build directory"
task :build, %i[buildenv] => %i[setenv] do |t, args|
Nanoc::CLI.run(["compile"])
end
desc "Produce the build directory on-demand"
task :watch, %i[buildenv] => %i[setenv nanoc:build] do |t, args|
require "listen"
Listen.to(dirs.content) {
Nanoc::CLI.run(["compile"])
}.start
sleep
rescue Interrupt
warn "SIGINT: exit"
exit
end
task :setenv, %i[buildenv] do |t, args|
ENV["SASS_PATH"] = File.join(dirs.content, "css")
ENV["buildenv"] = args.buildenv || ENV["buildenv"] || "development"
end
end

19
rake/tasks/server.rake Normal file
View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
desc "Start web server"
task :server, [:protocol] do |_t, args|
require "server"
h = args.to_h
p = h[:protocol] || "tcp"
n = File.basename(dirs.root)
o = if p == "unix"
{unix: nanoc.server.unix.path}
else
{host: nanoc.server.tcp.host, port: nanoc.server.tcp.port}
end
Process.setproctitle "rake server[#{p}] [#{n}]"
s = Server.dir(nanoc.output_dir, o)
s.start(block: true)
rescue Interrupt
s.stop
end

14
rake/tasks/t.rake Normal file
View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
namespace :t do
desc "Generate /json/<locale>/<surahid>/info.json from surahs.json"
task :"surahs.json" do
surahs = Ryo.from_json(path: File.join(dirs.content, "json", "surahs.json"))
Ryo.properties_of(surahs).each do |locale|
surahs[locale].each.with_index(1) do |surah, index|
File.write File.join(dirs.content, "json", locale, index.to_s, "info.json"),
JSON.pretty_generate(Ryo.table_of(surah, recursive: true))
end
end
end
end

View file

@ -0,0 +1,57 @@
# -*- mode: org -*-
** vNEXT
**** Remove ~kanit-regular.ttf~
This change falls back onto standard web fonts across all
languages. This should help decrease bundle size, and save
time processing the custom font during page load
**** Add src/js/main/vendor.ts
Add a new entry point that bundles preact, and other third
party dependencies. Third-party imports are now in a single
place rather than duplicated throughout app components
**** Reduce bundle size
Remove build artifacts and features that don't apply on
KaiOS (eg: opengraph tags)
**** Replace the play|pause icons
Replace the play and pause icons
**** Remove nanoc-gzip.rb
Unneccessary for a packaged KaiOS application
**** Remove loaders
Remove all loaders from ~/src/js/loaders/~, and the postman
package (~packages/typescript/postman~)
**** KaiOS fork
Fork a new branch: ~kaios/main~ dedicated to KaiOS
**** Add ~etc/~
Move a large portion of the website's configuration files to
the ~/etc~ directory
** v0.9.0
**** Add ~share/al-quran.reflectslight.io/documentation/~
Replace ~share/doc/al-quran.reflectslight.io~
**** Add new recitation
Add a new recitation by Hani ar-Rifai
**** Replace ~opengraph.rb~ with ~_opengraph.html.erb~
Simplify how we render opengraph meta tags
**** Move to nodejs for scss compiler
Replace the deprecated Ruby scss compiler with the nodejs compiler
**** Add ~audio.base_url~ to nanoc.yaml
Provide extra flexibility for audio content
**** Rename packages/typescript/Quran/ properties
Introduce urlName, translitName to Surah objects
**** eslint upgrade
Migrate to the most recent version of eslint (^9.8)

View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View file

@ -0,0 +1 @@
v0.9.0

View file

@ -0,0 +1,31 @@
# -*- mode: org -*-
** Introduction
This document explains the process that should be
followed when adding a new locale or language
to the website. Ideally the process would require
a minimal amount of manual work and be fast to complete
but we're not quite there yet.
** Steps
**** Add new locale to file ~/Rules~
The ~/Rules~ file has to be updated
**** Add new locale to array ~Quran.locales~
The ~/packages/Quran/src/index.ts~ file has to be updated
**** Add new locale (+ translations)
The following files have to updated:
+ ~/src/json/t.json~
+ ~/src/json/surahs.json~
+ ~/src/json/<locale>/<surahId>/{info,surah}.json~
**** Save time
The ~/src/json/<locale>/<surahId>/info.json~ files can
be generated from the contents of ~/src/json/surahs.json~ -
and that leaves us with one less step to complete:
#+BEGIN_SRC sh
user@localhost$ bundle exec rake t:surahs.json
#+END_SRC

53
src/css/_base.scss Normal file
View file

@ -0,0 +1,53 @@
@import "base/colors";
@import "base/breakpoints";
@import "base/icon";
@import "base/select";
@import "vendor/tail";
html {
height: 100%;
body {
height: 100%;
color: $black;
margin: 0;
.root {
height: 100%;
}
.ltr {
font-family: 'Arial', 'Tahoma', sans-serif;
direction: ltr;
}
.rtl {
font-family: 'Arial', 'Tahoma', sans-serif;
direction: rtl;
}
.invisible, .hidden {
display: none;
}
.outline-0 {
outline: 0;
}
.scroll-y {
overflow-y: auto;
}
}
}
body .root .content.theme {
margin: 0 auto;
max-width: $breakpoint-md;
width: 85%;
font-size: medium;
header {
a[data-testid="h1"] {
font-size: large;
}
}
}
/**
* RTL languages
*/
body .root .content.theme.rtl {
}

View file

@ -0,0 +1,10 @@
/* KaiOS: max widths */
$breakpoint-kaiOS-portrait: 240px;
$breakpoint-kaiOS-landscape: 320px;
/* Standard max widths */
$breakpoint-sm: 576px;
$breakpoint-md: 768px;
$breakpoint-lg: 992px;
$breakpoint-xl: 1200px;
$breakpoint-xxl: 1395px;

View file

@ -0,0 +1,2 @@
$black: #454545;
$white: #FFF;

114
src/css/base/_icon.scss Normal file
View file

@ -0,0 +1,114 @@
.stalled.icon {
display: inline-block;
position: relative;
left: 7px;
height: 4px;
div {
display: inline-block;
position: absolute;
left: 8px;
width: 5px;
animation: stalled 0.8s cubic-bezier(0, 0.5, 0.5, 1) infinite;
@keyframes stalled {
0% {
top: 4px;
height: 8px;
}
50%, 100% {
top: 8px;
height: 4px;
}
}
}
div:nth-child(1) {
left: 12px;
animation-delay: -0.24s;
}
div:nth-child(2) {
left: 20px;
animation-delay: -0.12s;
}
div:nth-child(3) {
left: 28px;
animation-delay: 0;
}
}
.root .content.theme {
.icon {
display: inline-block;
cursor: pointer;
}
.play.icon,
.pause.icon {
height: 16px;
width: 16px;
@media (min-width: $breakpoint-xxl) {
height: 20px;
width: 20px;
}
}
.refresh.icon,
.right-arrow.icon,
.left-arrow.icon {
height: 16px;
width: 16px;
}
.left-arrow.icon {
transform: rotate(180deg);
}
ul.body.stream span {
.sound-on.icon,
.sound-off.icon {
width: 24px;
height: 24px;
transform: translateY(5px);
}
}
footer {
.sound-on.icon,
.sound-off.icon {
transform: translateY(5px);
width: 24px;
height: 24px;
@media(min-width: $breakpoint-xxl) {
height: 28px;
width: 28px;
}
}
}
}
.root .content.theme.rtl {
.stalled.icon {
left: 0px;
right: 7px;
}
ul.body.stream {
li.ayah .sound-on.icon,
li.ayah .sound-off.icon {
transform: rotate(180deg) translateY(3px);
}
}
footer {
.sound-on.icon,
.sound-off.icon {
transform: rotate(180deg) translateY(5px);
}
.play.icon {
transform: rotate(180deg);
}
}
}

22
src/css/base/_select.scss Normal file
View file

@ -0,0 +1,22 @@
.root .content.theme {
.react-select {
z-index: 2;
.active {
cursor: pointer;
}
}
.react-select.theme-select {
.circle {
width: 16px;
height: 16px;
border-radius: 12px;
}
}
.react-select.language-select {
li a {
border: 1px solid $black;
}
}
}

View file

@ -0,0 +1,65 @@
@import "base";
@import "themes/blue";
@import "themes/green";
body .root .content.theme {
ul.body.index {
@media (max-width: $breakpoint-sm) {
li, li a {
width: 100%;
}
}
li.surah a {
&:visited, &:active, &:link {
text-decoration: none;
}
@media (max-width: $breakpoint-sm) {
span.transliterated, span.ayat {
display: none;
}
}
@media (hover: hover) {
&:hover {
background: rgba(220, 220, 220, 0.25);
}
}
}
}
footer {
/* TODO: Remove footer ? */
display: none;
}
}
/**
* RTL languages
*/
body .root .content.theme.rtl {
ul.body.index {
li a {
span:first-child {
border: 1px solid $black;
margin-left: 0.5rem;
}
}
li.surah {
span.transliterated { display: none; }
}
}
/* >= $breakpoint-xxl */
@media (min-width: $breakpoint-xxl) {
ul.body.index {
li.surah a {
span:last-child {
font-size: larger;
}
}
}
}
}

View file

@ -0,0 +1,55 @@
@import "base";
@import "themes/blue";
@import "themes/green";
body .root .content.theme {
ul.body.stream {
scrollbar-gutter: stable;
li.ayah.fade {
@keyframes FadeIn {
0% { opacity: 0;}
25% { opacity: 0.25; }
50% { opacity: 0.5; }
75% { opacity: 0.75 }
100% { opacity: 1; }
}
animation: FadeIn 1s;
}
}
ul.body.stream:focus {
outline: none;
}
}
body .root .content.theme.rtl {
ul.body.stream {
li.ayah p {
line-height: 1.7;
max-width: 470px;
}
}
/* <= $breakpoint-sm */
@media (max-width: $breakpoint-sm) {
ul.body.stream {
li.ayah p {
width: 100%;
}
}
}
/* >= $breakpoint-xxl */
@media (min-width: $breakpoint-xxl) {
ul.body.stream {
$gap: 2rem;
margin-top: $gap;
li.ayah {
font-size: larger;
margin-bottom: $gap;
}
}
footer {
.timer {
font-size: larger;
}
}
}
}

39
src/css/themes/blue.scss Normal file
View file

@ -0,0 +1,39 @@
.root .content.theme.blue.rtl {
direction: rtl;
}
.root .content.theme.blue {
@import "blue/base/colors";
.color-white {
color: $white;
}
.color-primary {
color: $primary-color;
}
.color-secondary {
color: $secondary-color;
}
.color-accent {
color: $accent-color;
}
.background-primary {
background: $primary-color;
}
.background-secondary {
background: $secondary-color;
}
.background-accent {
background: $accent-color;
}
}
@import "blue/base";
@import "blue/main/SurahIndex";
@import "blue/main/SurahStream";

View file

@ -0,0 +1,15 @@
@import "base/icon";
@import "base/select";
.root .content.theme.blue {
@import "base/colors";
scrollbar-color: $primary-color #FFF;
header {
a[data-testid="h1"] {
background: $primary-color;
border: 1px solid $black;
color: #FFF;
}
}
}

View file

@ -0,0 +1,4 @@
$primary-color: #3383C3;
$secondary-color: #3383C3;
$accent-color: lighten($primary-color, 38%);
$white: #FFF;

View file

@ -0,0 +1,40 @@
.content.theme.blue {
@import "themes/blue/base/colors";
ul.body.stream li, footer {
.play.icon {
fill: $primary-color;
stroke: $secondary-color;
stroke-width: 2px;
}
.pause.icon {
path {
fill: $primary-color;
stroke: $secondary-color;
stroke-width: 1px;
}
}
.refresh.icon {
fill: $primary-color;
}
.sound-on.icon, .sound-off.icon {
polygon {
fill: $primary-color;
stroke-width: 2;
}
}
.right-arrow.icon,
.left-arrow.icon {
g {
fill: $secondary-color;
}
}
}
.stalled.icon {
div { background: $secondary-color; }
}
}

View file

@ -0,0 +1,29 @@
.content.theme {
@import "themes/blue/base/colors";
.blue {
background: $secondary-color;
}
}
.content.theme.blue {
@import "themes/blue/base/colors";
.react-select.theme-select {
.active .circle {
background: $secondary-color;
}
ul li.blue .circle {
background: $secondary-color;
}
}
.react-select.language-select {
li a {
background: $secondary-color;
color: $white;
&:active, &:visited, &:link {
color: $white;
}
}
}
}

View file

@ -0,0 +1,58 @@
.root .surah-index.content.theme.blue {
@import "themes/blue/base/colors";
@import "base/breakpoints";
ul.body.index {
li.surah a {
&:active, &:link, &:visited {
color: $primary-color;
}
span:first-child {
border: 1px solid $black;
color: $white;
}
}
}
footer {
a {
&:active, &:link, &:visited {
color: $primary-color;
text-decoration: none;
}
&:hover {
font-weight: bold;
}
}
input {
border: 1px solid $secondary-color;
&:focus {
outline-color: $secondary-color;
}
}
}
}
.root .content.theme.blue.en {
@import "themes/blue/base/colors";
header {
div {
color: $secondary-color;
}
}
}
.root .content.theme.blue.rtl {
@import "themes/blue/base/colors";
ul.body.index {
li.surah a {
span.id {
color: $secondary-color;
}
span.name {
color: $primary-color;
}
}
}
}

View file

@ -0,0 +1,19 @@
.root .content.theme.blue {
@import "themes/blue/base/colors";
@import "base/breakpoints";
ul.body.stream {
li.ayah {
span span {
color: $secondary-color;
}
p { }
}
}
footer {
.timer {
color: $primary-color;
}
}
}

40
src/css/themes/green.scss Normal file
View file

@ -0,0 +1,40 @@
.root .content.theme.green.rtl {
@import "green/base/colors";
direction: rtl;
}
.root .content.theme.green {
@import "green/base/colors";
.color-primary {
color: $primary-color;
}
.color-secondary {
color: $secondary-color;
}
.color-accent {
color: $accent-color;
}
.color-white {
color: #FFF;
}
.background-primary {
background: $primary-color;
}
.background-secondary {
background: $secondary-color;
}
.background-accent {
background: $accent-color;
}
}
@import "green/base";
@import "green/main/SurahIndex";
@import "green/main/SurahStream";

View file

@ -0,0 +1,15 @@
@import "base/icon";
@import "base/select";
.root .content.theme.green {
@import "base/colors";
scrollbar-color: $primary-color #FFF;
header {
a[data-testid="h1"] {
background: $primary-color;
border: 1px solid $black;
color: #FFF;
}
}
}

View file

@ -0,0 +1,3 @@
$primary-color: #6d765b;
$secondary-color: #6C755A;
$accent-color: #FFF;

View file

@ -0,0 +1,41 @@
.content.theme.green {
@import "themes/green/base/colors";
ul.body.stream li, footer {
.play.icon {
g path {
fill: $primary-color;
stroke: $primary-color;
stroke-width: 3px;
}
}
.pause.icon {
g path {
fill: $primary-color;
stroke: $primary-color;
stroke-width: 1px;
}
}
.refresh.icon {
fill: $primary-color;
}
.sound-on.icon, .sound-off.icon {
g polygon {
fill: $primary-color;
}
}
.right-arrow.icon,
.left-arrow.icon {
g {
fill: $primary-color;
}
}
}
.stalled.icon {
div { background: $primary-color; }
}
}

View file

@ -0,0 +1,29 @@
.content.theme {
@import "themes/green/base/colors";
.green {
background: $primary-color;
}
}
.content.theme.green {
@import "themes/green/base/colors";
.react-select.theme-select {
.active {
.circle {
background: $primary-color;
border-radius: 10px;
}
}
}
.react-select.language-select {
li a {
background: $primary-color;
color: $white;
&:active, &:visited, &:link {
color: $white;
}
}
}
}

View file

@ -0,0 +1,31 @@
.root .surah-index.content.theme.green {
@import "base/breakpoints";
@import "themes/green/base/colors";
ul.body.index a {
&:active, &:link, &:visited {
color: $primary-color;
}
span:first-child {
border: 1px solid $black;
color: $white;
}
}
footer {
a {
&:active, &:link, &:visited {
color: $primary-color;
}
&:hover {
font-weight: bold;
}
}
input {
border: 1px solid $primary-color;
&:focus {
outline-color: $primary-color;
}
}
}
}

View file

@ -0,0 +1,29 @@
.root .content.theme.green {
@import "themes/green/base/colors";
@import "base/breakpoints";
header {
h1, h1 a { color: $primary-color; }
color: $primary-color;
}
ul.body.stream {
li.ayah {
color: $primary-color;
p { color: $black; }
}
}
footer {
.timer {
color: $primary-color;
}
}
.sound-on.icon, .svg.sound-off.icon {
polygon {
fill: $primary-color;
stroke-width: 2;
}
}
}

5303
src/css/vendor/tail.scss vendored Normal file

File diff suppressed because one or more lines are too long

BIN
src/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View file

@ -0,0 +1,6 @@
<link rel="icon" sizes="16x16" href="/images/favicon-16x16.png" />
<link rel="icon" sizes="32x32" href="/images/favicon-32x32.png" />
<link rel="icon" sizes="48x48" href="/images/favicon-48x48.png" />
<link rel="icon" sizes="64x64" href="/images/favicon-64x64.png" />
<link rel="icon" sizes="128x128" href="/images/favicon-128x128.png" />
<link rel="icon" sizes="256x256" href="/images/favicon-256x256.png" />

View file

@ -0,0 +1,2 @@
<meta name="version" content="<%= version %>">
<meta name="revision" content="<%= commit %>">

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="<%= context.locale %>" dir="<%= context.dir %>">
<head>
<title><%= t(context.locale, "TheNobleQuran") %></title>
<meta name="description" content="<%= t(context.locale, 'meta.random.description') %>">
<%= erb("_version.html.erb") %>
<link
rel="canonical"
href="<%= base_url %>/<%= context.locale %>/random/"
/>
<% context.locales.each do |locale| %>
<link
rel="alternate"
href="<%= base_url %>/<%= locale %>/random/"
hreflang="<%= locale %>" />
<% end %>
<%= erb("_favicon.html.erb") %>
</head>
<body>
<script src="/js/main/random.js?v=<%= commit %>"></script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title><%= t("en", "TheNobleQuran") %></title>
<meta name="description" content="<%= t('en', 'meta.index.description') %>">
<%= erb("_version.html.erb") %>
<link rel="canonical" href="<%= base_url %>/en/" />
<% locales.each do |locale| %>
<link
rel="alternate"
href="<%= base_url %>/<%= locale %>/"
hreflang="<%= locale %>" />
<% end %>
<%= erb("_favicon.html.erb") %>
</head>
<body>
<script src="/js/main/redirect.js?v=<%= commit %>"></script>
</body>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="<%= context.locale %>" dir="<%= context.dir %>">
<head>
<title><%= t(context.locale, "TheNobleQuran") %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta charset="UTF-8">
<meta name="description" content="<%= t(context.locale, 'meta.index.description') %>">
<%= erb("_version.html.erb") %>
<link
rel="canonical"
href="<%= base_url %>/<%= context.locale %>/"
/>
<% context.locales.each do |locale| %>
<link rel="alternate"
href="<%= base_url %>/<%= locale %>/"
hreflang="<%= locale %>" />
<% end %>
<%= erb("_favicon.html.erb") %>
</head>
<body>
<div class="root h-full"></div>
<script type="text/javascript" src="/js/main/vendor.js?v=<%= commit %>"></script>
<script type="text/javascript" src="/js/main/surah-index.js?v=<%= commit %>"></script>
</body>
</html>

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="<%= context.locale %>" dir="<%= context.dir %>">
<head>
<title><%= context.surah.name %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<meta name="description" content="<%= t(context.locale, 'meta.stream.description') %>">
<%= erb("_version.html.erb") %>
<link
rel="canonical"
href="<%= base_url %>/<%= context.locale %>/<%= context.surah.urlName %>/"
/>
<% context.locales.each do |locale| %>
<link rel="alternate"
href="<%= base_url %>/<%= locale %>/<%= context.surah.urlName %>/"
hreflang="<%= locale %>" />
<% end %>
<%= erb("_favicon.html.erb") %>
</head>
<body>
<div class="root"
data-surah-id="<%= context.surah.id %>"
data-audio-base-url="<%= audio_base_url %>">
</div>
<%= inline_json("/json/%{locale}/%{surah_id}/info.json", context:, class_name: "info") %>
<%= inline_json("/json/%{locale}/%{surah_id}/surah.json", context:, class_name: "surah") %>
<%= inline_json("/json/durations/%{surah_id}.json", context:, class_name: "durations") %>
<script src="/js/main/vendor.js?v=<%= commit %>"></script>
<script src="/js/main/surah-stream.js?v=<%= commit %>"></script>
</body>
</html>

BIN
src/images/favicon-128x128.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
src/images/favicon-16x16.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

BIN
src/images/favicon-256x256.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
src/images/favicon-32x32.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
src/images/favicon-48x48.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
src/images/favicon-64x64.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

17
src/images/favicon.svg Executable file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 457.43 358.056">
<g id="Calque_2" data-name="Calque 2" transform="scale(0.9) translate(0, 15)">
<g id="_01-_quran" data-name="01- quran" transform="scale(0.9) translate(0, 15)">
<path d="m198.551 46.33s11.042-28.077 41.994-46.33l178.721 13.64-123.041 144.872s-94.415-64.169-97.674-112.182z" fill="#f0e3e7" stroke="black" stroke-width="0.5"/>
<path d="m445.23 41.488-112.33 125.012-28.95 16.59-223.09-70.512-.07-.02-79.87-30.73 5.49-67.45s78.88-3.87 155.26 6.09c0 0 74.38 42.59 134.29 129.43 0 0 10.48-88.32 123.31-136.26z" fill="#fcf4f6" stroke="black" stroke-width="0.5"/>
<path d="m161.67 20.468c-9.99 51.44-28.46 75.41-28.46 75.41l-52.35 16.7-.07-.02-79.87-30.73 5.49-67.45s78.88-3.87 155.26 6.09z" fill="#f0e3e7" stroke="black" stroke-width="0.5"/>
<path d="m457.43 51.128-53.92 52.83-77.28 109.3-239.83-80.9-58.69-19.8-27.71-5.28.92-25.45 132.29 14.05 176.46 83.93 135.56-138.32z" fill="#ffb48d" stroke="black" stroke-width="0.5"/>
<path d="m133.21 95.878-4.17 38.18-42.64-1.7-58.69-19.8-27.71-5.28.92-25.45z" fill="#f5a27e" stroke="black" stroke-width="0.5"/>
<!-- Manually added stroke for blue areas -->
<path d="m453.57 268.438-17.75 30.05h-78.91l-337.34-157.37 8.14-28.56 137.84 18.72z" fill="#3383C3" stroke="black" stroke-width="0.5"/>
<path d="m435.82 298.488h-78.91l-337.34-157.37 130.2 19.4z" fill="#3383C3" stroke="black" stroke-width="0.5"/>
<path d="m290.414 228.353-84.615 121.474-145.539-54.202 107.307-85.463h.005z" fill="#3383C3" stroke="black" stroke-width="0.5"/>
<path d="m424.967 128.549-216.751 229.507-147.956-35.248v-27.183l141.298 30.459 201.955-222.13z" fill="#3383C3" stroke="black" stroke-width="0.5"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1,101 @@
import type { Surah, Ayah } from "Quran";
import { SoundOnIcon, SoundOffIcon } from "~/components/Icon";
export type TAudioStatus = "play" | "pause" | "wait" | "end";
type Maybe<T> = T | null | undefined;
type TChangeFuncs = [() => void, () => void];
type Props = {
audio: HTMLAudioElement;
surah: Surah;
ayah: Maybe<Ayah>;
enabled: boolean;
setEnabled: (v: boolean) => void;
hidden?: boolean;
onStatusChange?: (s: TAudioStatus, fns: TChangeFuncs) => void;
};
export function AudioControl({
audio,
surah,
ayah,
enabled,
setEnabled,
hidden = false,
onStatusChange = () => null,
}: Props) {
const [audioStatus, setAudioStatus] = useState<Maybe<TAudioStatus>>(null);
const [audioBaseUrl, setAudioBaseUrl] = useState<Maybe<string>>(null);
const play = (audio: HTMLAudioElement) => audio.play().catch(() => null);
const pause = (audio: HTMLAudioElement) => audio.pause();
useEffect(() => {
if (hidden || !ayah || !audio || !audioBaseUrl) {
return;
}
if (enabled) {
audio.src = [audioBaseUrl, surah.id, `${ayah.id}.mp3`].join("/");
play(audio);
}
}, [hidden, enabled, ayah?.id, audioBaseUrl]);
useEffect(() => {
const el: HTMLDivElement | null = document.querySelector(
"[data-audio-base-url]",
);
const url = el?.dataset?.audioBaseUrl;
if (url?.length) {
setAudioBaseUrl(url);
} else {
console.warn("audio.base_url is not set");
}
}, []);
useEffect(() => {
if (!audio || !ayah) {
return;
}
const onPlay = () => setAudioStatus("play");
const onPause = () => setAudioStatus("pause");
const onEnd = () => setAudioStatus("end");
const onWait = () => [setAudioStatus("wait"), play(audio)];
audio.addEventListener("play", onPlay);
audio.addEventListener("playing", onPlay);
audio.addEventListener("pause", onPause);
audio.addEventListener("ended", onEnd);
audio.addEventListener("stalled", onWait);
audio.addEventListener("waiting", onWait);
return () => {
audio.removeEventListener("play", onPlay);
audio.removeEventListener("playing", onPlay);
audio.removeEventListener("pause", onPause);
audio.removeEventListener("ended", onEnd);
audio.removeEventListener("stalled", onWait);
audio.removeEventListener("waiting", onWait);
};
}, [enabled, ayah?.id]);
useEffect(() => {
if (audioStatus) {
onStatusChange(audioStatus, [
() => setEnabled(true),
() => setEnabled(false),
]);
}
}, [audioStatus]);
if (hidden) {
return null;
}
return (
<>
{enabled && (
<SoundOnIcon onClick={() => [setEnabled(false), pause(audio)]} />
)}
{!enabled && (
<SoundOffIcon onClick={() => [setEnabled(true), play(audio)]} />
)}
</>
);
}

View file

@ -0,0 +1,30 @@
import type { ReactNode } from "react";
import type { TLocale } from "Quran";
import { Theme } from "~/hooks/useTheme";
type Props = {
title: string;
locale: TLocale;
theme: string;
setTheme: (t: Theme) => void;
children: ReactNode;
};
export function Head({ title, locale, children }: Props) {
return (
<header className="flex flex-col h-20 mt-4 mb-4">
<div className="flex flex-col">
<div className="flex items-center justify-center">
<a
data-testid="h1"
href={`/${locale.name}/index.html`}
className="flex rounded justify-center p-3 m-0 mb-4 w-full no-underline"
>
{title}
</a>
</div>
<nav className="flex flex-row justify-between">{children}</nav>
</div>
</header>
);
}

228
src/js/components/Icon.tsx Normal file
View file

@ -0,0 +1,228 @@
type Props = {
onClick: () => void;
};
export function PlayIcon({ onClick }: Props) {
return (
<svg
onClick={onClick}
version="1.1"
id="Capa_1"
xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
width="163.861px"
height="163.861px"
viewBox="0 0 163.861 163.861"
className="play icon"
>
<g>
<path
d="M34.857,3.613C20.084-4.861,8.107,2.081,8.107,19.106v125.637c0,17.042,11.977,23.975,26.75,15.509L144.67,97.275
c14.778-8.477,14.778-22.211,0-30.686L34.857,3.613z"
/>
</g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
<g></g>
</svg>
);
}
export function PauseIcon({ onClick }: Props) {
return (
<svg
onClick={onClick}
height="512"
className="pause icon"
viewBox="0 0 32 32"
width="512"
xmlns="http://www.w3.org/2000/svg"
>
<g id="Layer_33" data-name="Layer 33">
<path d="m14 5v22a3 3 0 0 1 -3 3h-3a3 3 0 0 1 -3-3v-22a3 3 0 0 1 3-3h3a3 3 0 0 1 3 3zm10-3h-3a3 3 0 0 0 -3 3v22a3 3 0 0 0 3 3h3a3 3 0 0 0 3-3v-22a3 3 0 0 0 -3-3z" />
</g>
</svg>
);
}
export function SoundOnIcon({ onClick }: Props) {
return (
<svg
viewBox="0 0 100 100"
preserveAspectRatio="xMidYMid meet"
className="sound-on icon"
onClick={onClick}
>
<g>
<polygon
fill="none"
stroke="#000000"
strokeWidth="2"
strokeMiterlimit="10"
points="3,32 3,20 15,20 33,2 33,32 33,62 15,44
3,44 "
/>
<path
fill="none"
stroke="#000000"
strokeWidth="2"
strokeMiterlimit="10"
d="M41,42c5.522,0,10-4.478,10-10s-4.478-10-10-10"
/>
<path
fill="none"
stroke="#000000"
strokeWidth="2"
strokeMiterlimit="10"
d="M41,12c11.046,0,20,8.954,20,20s-8.954,20-20,20"
/>
</g>
</svg>
);
}
export function SoundOffIcon({ onClick }: Props) {
return (
<svg
viewBox="0 0 100 100"
preserveAspectRatio="xMidYMid meet"
className="sound-off icon"
onClick={onClick}
>
<g>
<polygon
fill="none"
stroke="#000000"
strokeWidth="2"
strokeMiterlimit="10"
points="4,32 4,20 16,20 34,2 34,32 34,62 16,44
4,44 "
/>
<line
fill="none"
stroke="#000000"
strokeWidth="2"
strokeMiterlimit="10"
x1="42"
y1="23"
x2="60"
y2="41"
/>
<line
fill="none"
stroke="#000000"
strokeWidth="2"
strokeMiterlimit="10"
x1="42"
y1="41"
x2="60"
y2="23"
/>
</g>
</svg>
);
}
export function RefreshIcon({ onClick }: Props) {
return (
<svg
onClick={onClick}
className="refresh icon"
x="0px"
y="0px"
width="438.542px"
height="438.542px"
viewBox="0 0 438.542 438.542"
>
<g>
<path
d="M427.408,19.697c-7.803-3.23-14.463-1.902-19.986,3.999l-37.116,36.834C349.94,41.305,326.672,26.412,300.5,15.848
C274.328,5.285,247.251,0.003,219.271,0.003c-29.692,0-58.052,5.808-85.08,17.417c-27.03,11.61-50.347,27.215-69.951,46.82
c-19.605,19.607-35.214,42.921-46.824,69.949C5.807,161.219,0,189.575,0,219.271c0,29.687,5.807,58.05,17.417,85.079
c11.613,27.031,27.218,50.347,46.824,69.952c19.604,19.599,42.921,35.207,69.951,46.818c27.028,11.611,55.388,17.419,85.08,17.419
c32.736,0,63.865-6.899,93.363-20.7c29.5-13.795,54.625-33.26,75.377-58.386c1.52-1.903,2.234-4.045,2.136-6.424
c-0.089-2.378-0.999-4.329-2.711-5.852l-39.108-39.399c-2.101-1.711-4.473-2.566-7.139-2.566c-3.045,0.38-5.232,1.526-6.566,3.429
c-13.895,18.086-30.93,32.072-51.107,41.977c-20.173,9.894-41.586,14.839-64.237,14.839c-19.792,0-38.684-3.854-56.671-11.564
c-17.989-7.706-33.551-18.127-46.682-31.261c-13.13-13.135-23.551-28.691-31.261-46.682c-7.708-17.987-11.563-36.874-11.563-56.671
c0-19.795,3.858-38.691,11.563-56.674c7.707-17.985,18.127-33.547,31.261-46.678c13.135-13.134,28.693-23.555,46.682-31.265
c17.983-7.707,36.879-11.563,56.671-11.563c38.259,0,71.475,13.039,99.646,39.116l-39.409,39.394
c-5.903,5.711-7.231,12.279-4.001,19.701c3.241,7.614,8.856,11.42,16.854,11.42h127.906c4.949,0,9.23-1.807,12.848-5.424
c3.613-3.616,5.42-7.898,5.42-12.847V36.55C438.542,28.558,434.84,22.943,427.408,19.697z"
/>
</g>
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
</svg>
);
}
export function StalledIcon() {
return (
<div className="stalled icon flex justify-end w-10">
<div />
<div />
<div />
</div>
);
}
export function Arrow({ direction }: { direction: string }) {
return (
<svg
className={classNames(`${direction}-arrow`, "icon")}
viewBox="0 0 512.171 512.171"
>
<g>
<g>
<path
d="M509.035,248.212l-213.504-212.8c-3.051-3.029-7.595-3.904-11.627-2.304c-3.989,1.664-6.571,5.547-6.571,9.856v117.333
H10.667C4.779,160.298,0,165.076,0,170.964v170.667c0,5.888,4.779,10.667,10.667,10.667h266.667v116.885
c0,4.309,2.603,8.192,6.592,9.856c1.323,0.555,2.709,0.811,4.075,0.811c2.773,0,5.504-1.088,7.552-3.115l213.504-213.419
c2.005-2.005,3.115-4.715,3.115-7.552C512.171,252.927,511.04,250.218,509.035,248.212z"
/>
</g>
</g>
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
<g />
</svg>
);
}

View file

@ -0,0 +1,38 @@
import { Quran, TLocale } from "Quran";
import { Select } from "~/components/Select";
type Props = {
locale: TLocale;
isOpen: boolean;
setIsOpen: (v: boolean) => void;
};
export function LanguageSelect({ locale, isOpen, setIsOpen }: Props) {
return (
<Select
value={locale.name}
className="language-select w-20"
isOpen={isOpen}
setIsOpen={setIsOpen}
>
{Quran.locales.map((l: TLocale, i: number) => {
const path = location.pathname;
const href = path.replace(`/${locale.name}/`, `/${l.name}/`);
return (
<Select.Option
key={i}
className={classNames(
"flex h-5 text-sm w-full items-center justify-center no-underline mb-1 rounded",
l.direction,
l.name === locale.name ? "active" : undefined,
)}
value={l.name}
href={l.name === locale.name ? undefined : href}
>
{l.displayName}
</Select.Option>
);
})}
</Select>
);
}

View file

@ -0,0 +1,10 @@
import type { ReactNode, AnchorHTMLAttributes } from "react";
type Rest = AnchorHTMLAttributes<HTMLAnchorElement>;
type Props = {
value: string;
children: ReactNode;
} & Rest;
export function Option({ children, ...rest }: Props) {
return <a {...rest}>{children}</a>;
}

View file

@ -0,0 +1,34 @@
import { Select } from "~/components/Select";
import type { Theme } from "~/hooks/useTheme";
type Props = {
theme: string;
setTheme: (theme: Theme) => void;
isOpen: boolean;
setIsOpen: (b: boolean) => void;
};
export function ThemeSelect({ theme, setTheme, isOpen, setIsOpen }: Props) {
const themes: Theme[] = ["blue", "green"];
return (
<Select
value={theme}
className="theme-select"
isOpen={isOpen}
setIsOpen={setIsOpen}
>
{themes.map((t, i) => {
return (
<Select.Option
key={i}
onClick={() => setTheme(t)}
className={classNames("block circle mb-1", t)}
value={t}
>
<span className="block w-full h-full" />
</Select.Option>
);
})}
</Select>
);
}

View file

@ -0,0 +1,60 @@
import { Option } from "./Option";
import { ThemeSelect } from "./ThemeSelect";
import { LanguageSelect } from "./LanguageSelect";
type Props = {
isOpen: boolean;
setIsOpen: (v: boolean) => void;
value: string;
children: JSX.Element[];
className?: string;
};
function Select({
value,
children: options,
className,
isOpen,
setIsOpen,
}: Props) {
const [option, setOption] = useState<JSX.Element | null>(null);
const sortedOptions = options.sort((n) => (value === n.props.value ? -1 : 1));
const close = () => setIsOpen(false);
useEffect(() => {
document.body.addEventListener("click", close);
return () => document.body.removeEventListener("click", close);
}, []);
useEffect(() => {
setOption(options.find((n) => value === n.props.value) || null);
}, [value]);
return (
<div
className={classNames(
"react-select flex flex-col h-full relative",
className,
)}
>
<ul className="m-0 p-0 list-none text-base h-full mb-5">
{sortedOptions.map((n: JSX.Element, key: number) => {
const isHidden = !isOpen && option?.props.value !== n.props.value;
return (
<li
key={key}
className={classNames({ hidden: isHidden })}
onClick={(e) => [e.stopPropagation(), setIsOpen(!isOpen)]}
>
{n}
</li>
);
})}
</ul>
</div>
);
}
Select.Option = Option;
export { Select, LanguageSelect, ThemeSelect };

View file

@ -0,0 +1,40 @@
import { TFunction, formatNumber } from "~/lib/t";
import type { Surah, TLocale } from "Quran";
type Props = {
locale: TLocale;
t: TFunction;
setIndex: (k: Surah[]) => void;
surahs: Surah[];
};
export function Filter({ locale, t, setIndex, surahs }: Props) {
const onInput = (e: React.ChangeEvent<HTMLInputElement>) => {
const {
target: { value },
} = e;
if (value === "") {
setIndex(surahs);
} else {
const regexp = new RegExp(value, "i");
const newIndex = surahs.filter(
(surah) =>
regexp.test(surah.name) ||
regexp.test(surah.translitName) ||
regexp.test(String(surah.id)) ||
regexp.test(formatNumber(locale, surah.id)),
);
setIndex(newIndex);
}
};
return (
<input
data-testid="SurahIndex/Filter"
className="p-3 h-2 text-base color-primary rounded outline-0"
type="text"
placeholder={t(locale, "filter")}
onChange={onInput}
/>
);
}

View file

@ -0,0 +1,126 @@
import type { Surah, TLocale } from "Quran";
import { useTheme } from "~/hooks/useTheme";
import { formatNumber, TFunction } from "~/lib/t";
import { Arrow } from "~/components/Icon";
import { Head } from "~/components/Head";
import { LanguageSelect, ThemeSelect } from "~/components/Select";
import { Filter } from "./Filter";
import "@css/main/SurahIndex.scss";
type Props = {
locale: TLocale;
surahs: Surah[];
t: TFunction;
};
export function SurahIndex({ locale, surahs, t }: Props) {
const [theme, setTheme] = useTheme();
const [index, setIndex] = useState<Surah[]>(surahs);
const [showLangDropdown, setShowLangDropdown] = useState<boolean>(false);
const [showThemeDropdown, setShowThemeDropdown] = useState<boolean>(false);
const rootRef = useRef<HTMLDivElement>(null);
const activeEl = useMemo(
() => document.activeElement,
[document.activeElement]
)
useEffect(() => {
const onKeyPress = (e) => {
if (e.key === "SoftLeft") {
setShowLangDropdown(!showLangDropdown);
} else if (e.key === "SoftRight") {
setShowThemeDropdown(!showThemeDropdown);
}
};
activeEl.addEventListener("keydown", onKeyPress);
return () => activeEl.removeEventListener("keydown", onKeyPress);
}, [activeEl, showLangDropdown, showThemeDropdown]);
useEffect(() => {
const el = rootRef.current;
if (el) {
el.classList.remove("invisible");
}
}, [rootRef.current, theme]);
return (
<div
ref={rootRef}
className={classNames(
"flex flex-col invisible h-full content surah-index theme",
theme,
locale.name,
locale.direction,
)}
>
<Head title={t(locale, "TheNobleQuran")} locale={locale}>
<LanguageSelect
isOpen={showLangDropdown}
setIsOpen={setShowLangDropdown}
locale={locale}
/>
<ThemeSelect
isOpen={showThemeDropdown}
setIsOpen={setShowThemeDropdown}
theme={theme}
setTheme={setTheme}
/>
</Head>
<ul className="flex flex-wrap body index scroll-y list-none m-0 p-0 w-full h-full">
{index.map((surah, key) => (
<li
className={classNames("flex justify-center surah", {
"w-full": locale.direction === "ltr",
"w-1/2": locale.direction === "rtl",
})}
key={key}
>
<a
className="flex items-center color-primary no-underline rounded w-11/12 h-8"
href={`/${locale.name}/${surah.urlName}/index.html`}
>
<span className="background-secondary color-white rounded flex w-8 font-extrabold w-5 mr-3 justify-center text-center">
{formatNumber(locale, surah.id)}
</span>
<span>{surah.name}</span>
{locale.direction === "ltr" && (
<div className="flex justify-end grow pr-3">
<div className="flex flex-col">
<span className="transliterated" lang="en">
{surah.translitName}
</span>
<span className="ayat flex justify-end text-sm">
{formatNumber(locale, surah.numberOfAyah)}{" "}
{t(locale, "ayat")}
</span>
</div>
</div>
)}
</a>
</li>
))}
</ul>
<footer className="flex flex-row justify-between mb-5 h-12">
<a
className="flex flex-row items-center no-underline"
href={`/${locale.name}/random/`}
>
{locale.direction === "ltr" ? (
<Arrow direction="right" />
) : (
<Arrow direction="left" />
)}
<span
className={classNames({
"pl-3": locale.direction === "ltr",
"pr-3": locale.direction === "rtl",
})}
>
{t(locale, "ChooseRandomChapter")}
</span>
</a>
<Filter t={t} locale={locale} surahs={surahs} setIndex={setIndex} />
</footer>
</div>
);
}

View file

@ -0,0 +1,66 @@
import type { Surah, Ayah, TAyat, TLocale } from "Quran";
import { formatNumber, TFunction } from "~/lib/t";
type Props = {
locale: TLocale;
surah: Surah;
stream: TAyat;
endOfStream: boolean;
isPaused: boolean;
t: TFunction;
};
export function Stream({
locale,
surah,
stream,
endOfStream,
isPaused,
t,
}: Props) {
const className = endOfStream || isPaused ? ["scroll-y"] : [];
const ref = useRef<HTMLUListElement>(null);
const ul = useMemo<JSX.Element>(() => {
const ltr = locale.direction === "ltr";
const rtl = locale.direction === "rtl";
return (
<ul
lang={locale.name}
className={classNames(
"body stream scroll-y list-none p-0 m-0 h-5/6",
...className,
)}
ref={ref}
>
{stream.map((ayah: Ayah) => {
return (
<li
key={ayah.id}
className={classNames("ayah fade", { "mb-1": rtl || ltr })}
>
<span className="flex h-8 items-center">
<span>
{t(locale, "surah")} {formatNumber(locale, surah.id)}
{t(locale, "comma")} {t(locale, "ayah")}{" "}
{formatNumber(locale, ayah.id)} {t(locale, "of")}{" "}
{formatNumber(locale, surah.ayat.length)}
</span>
</span>
<p className="m-0">{ayah.body}</p>
</li>
);
})}
</ul>
);
}, [stream.length, isPaused, endOfStream]);
useEffect(() => {
const el = ref.current;
if (el) {
el.focus();
el.scrollTop = el.scrollHeight;
}
}, [stream.length]);
return ul;
}

View file

@ -0,0 +1,176 @@
import classNames from "classnames";
import type { Surah, Ayah, TAyat, TLocale } from "Quran";
import { useTheme } from "~/hooks/useTheme";
import { AudioControl, TAudioStatus } from "~/components/AudioControl";
import { LanguageSelect, ThemeSelect } from "~/components/Select";
import { Head } from "~/components/Head";
import {
PlayIcon,
PauseIcon,
RefreshIcon,
StalledIcon,
} from "~/components/Icon";
import { Timer } from "~/components/Timer";
import { TFunction } from "~/lib/t";
import { Stream } from "./Stream";
import "@css/main/SurahStream.scss";
type Maybe<T> = T | null | undefined;
type Props = {
surah: Surah;
locale: TLocale;
t: TFunction;
};
export function SurahStream({ surah, locale, t }: Props) {
const [stream, setStream] = useState<TAyat>([]);
const [isPaused, setIsPaused] = useState<boolean>(false);
const [audioEnabled, setAudioEnabled] = useState<boolean>(false);
const [audioStatus, setAudioStatus] = useState<Maybe<TAudioStatus>>(null);
const [endOfStream, setEndOfStream] = useState<boolean>(false);
const [showLangDropdown, setShowLangDropdown] = useState<boolean>(false);
const [showThemeDropdown, setShowThemeDropdown] = useState<boolean>(false);
const [theme, setTheme] = useTheme();
const rootRef = useRef<HTMLElement>(null);
const audio = useMemo(() => new Audio(), []);
const readyToRender = stream.length > 0;
const ayah: Maybe<Ayah> = stream[stream.length - 1];
const activeEl = useMemo(
() => document.activeElement,
[document.activeElement],
);
useEffect(() => {
if (showLangDropdown || showThemeDropdown) {
setIsPaused(true);
} else {
setIsPaused(false);
}
}, [showLangDropdown, showThemeDropdown]);
useEffect(() => {
const onKeyPress = (e) => {
if (e.key === "Backspace") {
e.preventDefault();
location.href = `/${locale.name}/index.html`;
} else if (e.key === "SoftLeft") {
setShowLangDropdown(!showLangDropdown);
} else if (e.key === "SoftRight") {
setShowThemeDropdown(!showThemeDropdown);
} else if (e.key === "ArrowLeft") {
if (endOfStream) {
setEndOfStream(false);
} else {
setIsPaused(!isPaused);
}
}
};
activeEl.addEventListener("keydown", onKeyPress);
return () => activeEl.removeEventListener("keydown", onKeyPress);
}, [activeEl, showLangDropdown, showThemeDropdown]);
useEffect(() => {
const el = rootRef.current;
if (el) {
el.classList.remove("invisible");
}
}, [rootRef.current, theme]);
useEffect(() => {
if (!endOfStream) {
setStream([surah.ayat[0]]);
}
}, [endOfStream]);
return (
<article
ref={rootRef}
className={classNames(
"flex flex-col invisible h-full content theme",
locale.name,
locale.direction,
theme,
{ hidden: !readyToRender },
)}
>
<Head title={t(locale, "TheNobleQuran")} locale={locale}>
<LanguageSelect
locale={locale}
isOpen={showLangDropdown}
setIsOpen={setShowLangDropdown}
/>
<ThemeSelect
theme={theme}
setTheme={setTheme}
isOpen={showThemeDropdown}
setIsOpen={setShowThemeDropdown}
/>
</Head>
<Stream
surah={surah}
stream={stream}
locale={locale}
endOfStream={endOfStream}
isPaused={isPaused}
t={t}
/>
<footer className="flex justify-between items-center h-16">
{!endOfStream && isPaused && (
<PlayIcon onClick={() => setIsPaused(false)} />
)}
{!endOfStream && !isPaused && (
<PauseIcon onClick={() => setIsPaused(true)} />
)}
<span
className={classNames("sound-box flex flex-col items-end w-16", {
hidden: endOfStream,
})}
>
<AudioControl
audio={audio}
surah={surah}
ayah={ayah}
hidden={endOfStream}
enabled={audioEnabled}
setEnabled={setAudioEnabled}
onStatusChange={(status) => {
if (status === "end") {
setAudioEnabled(false);
}
setAudioStatus(status);
}}
/>
</span>
<span
className={classNames({
hidden: endOfStream || audioStatus === "wait",
})}
>
<Timer
locale={locale}
surah={surah}
ayah={ayah}
isPaused={isPaused}
audio={audio}
audioStatus={audioStatus}
onComplete={(surah, ayah) => {
const layah = surah.ayat[surah.ayat.length - 1];
if (!layah || !ayah) {
return;
} else if (layah.id === ayah.id) {
setEndOfStream(true);
} else {
setStream([...stream, surah.ayat[ayah.id]]);
}
}}
/>
</span>
{audioStatus === "wait" && <StalledIcon />}
<span className={classNames({ hidden: !endOfStream })}>
<RefreshIcon onClick={() => [setEndOfStream(false)]} />
</span>
</footer>
</article>
);
}

View file

@ -0,0 +1,75 @@
import type { Surah, Ayah, TLocale } from "Quran";
import { formatNumber } from "~/lib/t";
type Maybe<T> = T | null | undefined;
type Props = {
locale: TLocale;
surah: Surah;
ayah: Maybe<Ayah>;
isPaused: boolean;
audio: HTMLAudioElement;
audioStatus: Maybe<string>;
onComplete: (surah: Surah, ayah: Ayah) => void;
};
export function Timer({
locale,
surah,
ayah,
isPaused,
audio,
audioStatus,
onComplete,
}: Props) {
const [ms, setMs] = useState<number | null>(null);
const isStalled = audioStatus === "wait";
function getMs() {
const fallback =
audioStatus === null || audioStatus === "pause" || isNaN(audio.duration);
if (fallback) {
console.info("timer: length determined by ayah.ms");
return ayah?.ms || 0;
} else {
console.info("timer: length determined by HTMLAudioElement");
return audio.duration * 1000;
}
}
useEffect(() => {
if (ayah) {
setMs(getMs());
}
}, [ayah?.id]);
useEffect(() => {
if (audioStatus === "play") {
setMs(getMs());
}
}, [audioStatus]);
useEffect(() => {
const noop = !ayah || typeof ms !== "number" || isStalled || isPaused;
if (noop) {
return;
} else if (ms <= 0) {
onComplete(surah, ayah);
} else {
const tid = setTimeout(() => setMs(ms - 100), 100);
return () => clearTimeout(tid);
}
}, [isStalled, isPaused, ms]);
if (isStalled) {
return null;
}
return (
<div className="timer text-base w-10 flex justify-end">
{!ms || ms / 1000 <= 0
? formatNumber(locale, 0)
: formatNumber(locale, ms / 1000, { maximumFractionDigits: 0 })}
</div>
);
}

21
src/js/hooks/useTheme.ts Normal file
View file

@ -0,0 +1,21 @@
export type Theme = "blue" | "green";
type Result = [Theme, (t: Theme) => void];
const THEMES: Theme[] = ["blue", "green"];
const DEFAULT_THEME = "blue";
export function useTheme(): Result {
const cookies = Object.fromEntries(
document.cookie.split(";").map((e) => e.split("=")),
);
const [theme, setTheme] = useState<Theme>(
THEMES.find((t) => t === cookies.theme) || DEFAULT_THEME,
);
const set = (t: Theme) => {
if (THEMES.includes(t)) {
const maxAge = 3600 * 24 * 90;
document.cookie = `theme=${t}; path=/; max-age=${maxAge}; SameSite=Strict`;
setTheme(t);
}
};
return [theme, set];
}

30
src/js/lib/t.ts Normal file
View file

@ -0,0 +1,30 @@
import type { TLocale } from "Quran";
type PhraseMap<T> = {
[key: string]: undefined | string | PhraseMap<T>;
};
export type TFunction = (locale: TLocale, key: string) => string;
export function T(phrases: PhraseMap<string>): TFunction {
return function (locale: TLocale, key: string) {
const path = key.split(".");
const phrase = path.reduce(
(o, k) => (typeof o === "object" ? o[k] : o),
phrases[locale.name],
);
return typeof phrase === "string" ? phrase : key;
};
}
export function formatNumber(
locale: TLocale,
num: number,
options = {},
): string {
const numl = locale.name === "ar" ? "ar-SA" : locale.name;
return new Intl.NumberFormat(numl, {
maximumFractionDigits: 1,
...options,
}).format(num);
}

7
src/js/main/random.ts Normal file
View file

@ -0,0 +1,7 @@
(function () {
const nameById = require("@json/nameById.json");
const surahId = parseInt(Math.ceil(Math.random() * 114));
const name = nameById[surahId];
const locale = location.pathname.slice(1, 3);
location.replace(["", locale, name, ""].join("/"));
})();

10
src/js/main/redirect.ts Normal file
View file

@ -0,0 +1,10 @@
import { Quran } from "Quran";
(function () {
const defaultl = "en";
const locales = Quran.locales.map((l) => l.name);
const locale =
navigator.languages
.map((s) => s.slice(0, 2).toLowerCase())
.find((s) => locales.includes(s)) || defaultl;
location.replace(`/${locale}/`);
})();

View file

@ -0,0 +1,17 @@
import { Surah, TSurah, Quran } from "Quran";
import { T } from "~/lib/t";
import { SurahIndex } from "~/components/SurahIndex";
(function () {
const doc = document.documentElement;
const root = doc.querySelector(".root")!;
const t = T(require("@json/t.json"));
const byLocale = require("@json/surahs");
const locale = (() => {
return Quran.locales.find((ll) => ll.name === doc.lang);
})()!;
const surahs: Surah[] = byLocale[locale.name].map(
(e: TSurah) => new Surah(e),
);
render(<SurahIndex locale={locale} surahs={surahs} t={t} />, root);
})();

View file

@ -0,0 +1,34 @@
import { Quran, Surah, Ayah, TSurah } from "Quran";
import { T } from "~/lib/t";
import { SurahStream } from "~/components/SurahStream";
(function () {
const doc = document.documentElement;
const root = doc.querySelector(".root")!;
const t = T(require("@json/t.json"));
const locale = (() => {
return Quran.locales.find((ll) => ll.name === doc.lang);
})()!;
/*
* Configure an instance of Surah
*/
const node1: HTMLScriptElement = doc.querySelector(".json.info")!;
const node2: HTMLScriptElement = doc.querySelector(".json.surah")!;
const node3: HTMLScriptElement = doc.querySelector(".json.durations")!;
const blob1: TSurah = JSON.parse(node1.innerText)!;
const blob2: Array<[number, string]> = JSON.parse(node2.innerText)!;
const blob3: Array<[number, number]> = JSON.parse(node3.innerText)!;
const surah = new Surah(blob1);
for (let i = 0; i < blob2.length; i++) {
const [id, body] = blob2[i] as [number, string];
surah.ayat.push(new Ayah({ id, body }));
}
for (let i = 0; i < surah.ayat.length; i++) {
const ayah = surah.ayat[i];
const [, ms] = blob3[i];
ayah.ms = ms * 1000;
}
render(<SurahStream surah={surah} locale={locale} t={t} />, root);
})();

16
src/js/main/vendor.ts Normal file
View file

@ -0,0 +1,16 @@
import { render } from "preact";
import { useState, useEffect, useMemo, useRef } from "preact/hooks";
import * as React from "preact/compat";
import classNames from "classnames";
import "core-js";
const exports = {
React,
render,
useState,
useEffect,
useMemo,
useRef,
classNames,
};
Object.assign(window, exports);

8
src/json/ar/1/info.json Normal file
View file

@ -0,0 +1,8 @@
{
"id": 1,
"name": "الفاتحة",
"numberOfAyah": 7,
"translatedBy": null,
"urlName": "al-fatihah",
"translitName": "Al-Fatihah"
}

1
src/json/ar/1/surah.json Normal file
View file

@ -0,0 +1 @@
[[1,"بِسْمِ اللَّهِ الرَّحْمَـٰنِ الرَّحِيمِ"],[2,"الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ"],[3,"الرَّحْمَـٰنِ الرَّحِيمِ"],[4,"مَالِكِ يَوْمِ الدِّينِ"],[5,"إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ"],[6,"اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ"],[7,"صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ"]]

8
src/json/ar/10/info.json Normal file
View file

@ -0,0 +1,8 @@
{
"id": 10,
"name": "يونس",
"numberOfAyah": 109,
"translatedBy": null,
"urlName": "yunus",
"translitName": "Yunus"
}

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show more