Skip to content

Commit 4514b9c

Browse files
committed
fix root problem
1 parent 563bead commit 4514b9c

39 files changed

+334
-143
lines changed

design/file-structure.mmap

35.8 KB
Binary file not shown.
35.7 KB
Binary file not shown.

php/host.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
start msedge http://localhost:8000
2+
php -S localhost:8000

php/index.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$html = new simple_html_dom();
3+
$html->load('<html><body>从字符串中加载html文档演示</body></html>');

php/run.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
php -f index.php
2+
pause

src/.htaccess

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
RewriteEngine on
22
RewriteCond %{REQUEST_URI} ^.*/.+\.md$ [OR]
33
RewriteCond %{REQUEST_URI} ^.*/[^\.]+$
4-
RewriteRule ^ mdweb/index.php [L]
4+
RewriteRule ^ index.php [L]

src/_ending.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## left-1
44

5+
left-1
6+
57
- [privacy](privacy.md)
68
- [term](term.md)
79

src/_footer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# footer
22

33
---
4-
Copyright © 2021 [forw.cc](http://forw.cc)
4+
Copyright 2021 [forw.cc](http://forw.cc)
55
All rights reserved

src/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"keywords":"",
3-
"mode": "text"
3+
"mode": "ucp"
44
}

src/default.md

+91-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,99 @@
11
# Home
22

3-
<p>
4-
<center><i>A case solution for all</i></center>
5-
</p>
3+
![banner](image/banner.jpg)
64

7-
![main](image/main.gif)
5+
<center><i>page description</i></center>
86

7+
## h2-1
98

9+
![](image/shirt.svg)
1010

11+
unit description
1112

13+
## h2-2
14+
15+
###
16+
17+
![](image/teacher.svg)
18+
19+
card description
20+
21+
## h2-3
22+
23+
unit description
24+
25+
### h3-1
26+
27+
![](image/record.svg)
28+
29+
card description
30+
31+
### h3-2
32+
33+
![](image/record.svg)
34+
35+
card description
36+
37+
## h2-4
38+
39+
unit description
40+
41+
### h3-1
42+
43+
![](image/cart.svg)
44+
45+
card description
46+
47+
- [item](nav-1/dir-1/doc-1.md)
48+
<br>
49+
<br>
50+
<br>
51+
52+
#### h4
53+
54+
![](image/record.svg)
55+
56+
pop description
57+
58+
- item
59+
- item
60+
61+
### h3-2
62+
63+
![](image/cart.svg)
64+
65+
card description
66+
67+
- [item](nav-1/dir-2/doc-2.md)
68+
- item
69+
<br>
70+
<br>
71+
72+
#### h4
73+
74+
![](image/record.svg)
75+
76+
pop description
77+
78+
- item
79+
- item
80+
81+
### h3-3
82+
83+
![](image/cart.svg)
84+
85+
card description
86+
87+
- [item](nav-2/doc-3.md)
88+
- item
89+
- item
90+
91+
#### h4
92+
93+
![](image/record.svg)
94+
95+
pop description
96+
97+
- [item](nav-2/doc-4.md)
98+
- item
1299

src/index.php

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
/*
3+
file_path
4+
file_name
5+
dir_path
6+
dir_name
7+
8+
data = doc + config
9+
doc = main + header + ending + footer
10+
*/
11+
include "markdown-website/module/Parsedown.php";
12+
include "markdown-website/module/heading-array.php";
13+
14+
ini_set("display_errors", "On");
15+
date_default_timezone_set("Asia/Shanghai");
16+
//header('Access-Control-Allow-Origin:*');
17+
//header('Access-Control-Allow-Methods:*');
18+
//header('Access-Control-Allow-Headers:X-Requested-With,X_Requested_With');
19+
20+
// config
21+
$config_file_path = "markdown-website/config.json";
22+
if (file_exists($config_file_path)) {
23+
$json = file_get_contents($config_file_path);
24+
$config = json_decode($json, true);
25+
}
26+
27+
// request
28+
// fimik.com/src/tutorial/default.md, fimik.com/src/tutorial/, fimik.com/src/tutorial
29+
$script_name = $_SERVER['SCRIPT_NAME']; // /src/mdweb/index.php, /src/mdweb/index.php, /src/mdweb/index.php
30+
$request_uri = $_SERVER['REQUEST_URI']; // /src/tutorial/default.md, /src/tutorial/, /src/tutorial/
31+
// start dir path
32+
// get the same part at the left of $script_name and $request_uri, it is the $start_dir_path
33+
$the_same_length = strspn($script_name ^ $request_uri, "\0");
34+
$start_dir_path = substr($script_name, 0, $the_same_length); // /src/, /src/, /src/
35+
36+
// header
37+
$doc_header_file_path = "_header.md";
38+
if (file_exists($doc_header_file_path)) {
39+
$md = file_get_contents($doc_header_file_path);
40+
$Parsedown = new Parsedown();
41+
$html = $Parsedown->text($md);
42+
// add start dir path to the front
43+
$xml = new DOMDocument('1.0','UTF-8');
44+
$xml->loadHTML($html);
45+
foreach($xml->getElementsByTagName('a') as $link) {
46+
$old_link = $link->getAttribute("href");
47+
if (!filter_var($old_link, FILTER_VALIDATE_URL)) {
48+
// not url
49+
$link->setAttribute('href', $start_dir_path . $old_link);
50+
}
51+
}
52+
$html = $xml->saveHtml();
53+
$array = heading_parse($html);
54+
foreach ($array['h1'] as $h1) {
55+
if ($h1['title'] == 'header') {
56+
foreach ($h1['h2'] as $h2) {
57+
if ($h2['title'] == 'nav') {
58+
$header['nav'] = $h2['content'];
59+
}
60+
}
61+
}
62+
}
63+
}
64+
// ending
65+
$doc_ending_file_path = "_ending.md";
66+
if (file_exists($doc_ending_file_path)) {
67+
$md = file_get_contents($doc_ending_file_path);
68+
$Parsedown = new Parsedown();
69+
$html = $Parsedown->text($md);
70+
// add start dir path to the front
71+
$xml = new DOMDocument('1.0','UTF-8');
72+
$xml->loadHTML($html);
73+
foreach($xml->getElementsByTagName('a') as $link) {
74+
$old_link = $link->getAttribute("href");
75+
if (!filter_var($old_link, FILTER_VALIDATE_URL)) {
76+
// not url
77+
$link->setAttribute('href', $start_dir_path . $old_link);
78+
}
79+
}
80+
$html = $xml->saveHtml();
81+
$array = heading_parse($html);
82+
foreach ($array['h1'] as $h1) {
83+
if ($h1['title'] == 'ending') {
84+
foreach ($h1['h2'] as $h2) {
85+
if ($h2['title'] == 'left-1') {
86+
$ending['left-1'] = $h2['content'];
87+
}
88+
if ($h2['title'] == 'left-2') {
89+
$ending['left-2'] = $h2['content'];
90+
}
91+
if ($h2['title'] == 'left-3') {
92+
$ending['left-3'] = $h2['content'];
93+
}
94+
if ($h2['title'] == 'left-4') {
95+
$ending['left-4'] = $h2['content'];
96+
}
97+
if ($h2['title'] == 'right') {
98+
$ending['right'] = $h2['content'];
99+
}
100+
}
101+
}
102+
}
103+
}
104+
// footer
105+
$doc_footer_file_path = "_footer.md";
106+
if (file_exists($doc_footer_file_path)) {
107+
$md = file_get_contents($doc_footer_file_path);
108+
$Parsedown = new Parsedown();
109+
$html = $Parsedown->text($md);
110+
// add start dir path to the front
111+
$xml = new DOMDocument('1.0','UTF-8');
112+
$xml->loadHTML($html);
113+
foreach($xml->getElementsByTagName('a') as $link) {
114+
$old_link = $link->getAttribute("href");
115+
if (!filter_var($old_link, FILTER_VALIDATE_URL)) {
116+
// not url
117+
$link->setAttribute('href', $start_dir_path . $old_link);
118+
}
119+
}
120+
$html = $xml->saveHtml();
121+
$array = heading_parse($html);
122+
foreach ($array['h1'] as $h1) {
123+
if ($h1['title'] == 'footer') {
124+
$footer = $h1['content'];
125+
}
126+
}
127+
}
128+
// main
129+
$request_uri_no_start = substr($request_uri, strlen($start_dir_path)); // tutorial/default.md, tutorial/, tutorial
130+
if ($request_uri_no_start == "") {
131+
$doc_main_file_path = "default.md";
132+
} elseif (substr($request_uri_no_start, -1) == "/") {
133+
$doc_main_file_path = $request_uri_no_start . "default.md";
134+
} elseif (substr($request_uri_no_start, -3) == ".md") {
135+
$doc_main_file_path = $request_uri_no_start;
136+
} else {
137+
$doc_main_file_path = $request_uri_no_start . "/default.md";
138+
}
139+
if (!file_exists($doc_main_file_path)) {
140+
$doc_main_file_path = "404.md";
141+
}
142+
$work_dir_path = $start_dir_path . dirname($doc_main_file_path) . '/';
143+
$md = file_get_contents($doc_main_file_path);
144+
$Parsedown = new Parsedown();
145+
$html = $Parsedown->text($md);
146+
$array = heading_parse($html);
147+
$main = $array;
148+
// meta
149+
$meta_file_path = substr($doc_main_file_path, 0, -3) . ".json";
150+
if (file_exists($meta_file_path)) {
151+
$json = file_get_contents($meta_file_path);
152+
$meta = json_decode($json, true);
153+
}
154+
// echo "<p>";
155+
// var_dump($request_uri_no_start);
156+
// echo "</p>";
157+
// var_dump(glob('*'));
158+
// echo PHP_EOL;
159+
// exit();
160+
switch (@$meta["mode"]) {
161+
case "ucp":
162+
include "markdown-website/view/ucp.php";
163+
break;
164+
case "itti":
165+
include "markdown-website/view/itti.php";
166+
break;
167+
case "text":
168+
include "markdown-website/view/text.php";
169+
break;
170+
default:
171+
include "markdown-website/view/text.php";
172+
}
File renamed without changes.

src/mdweb/index.php src/markdown-website/index.php

+7-19
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@
3333
$the_same_length = strspn($script_name ^ $request_uri, "\0");
3434
$start_dir_path = substr($script_name, 0, $the_same_length); // /src/, /src/, /src/
3535

36-
// $script_dir_path = dirname($script_name); // /src, /src, /src
37-
// $script_dir_path_no_start = ltrim($script_dir_path, $start_dir_path); // "", "", ""
38-
// $request_dir_path = dirname($request_uri); // /src/tutorial, /src, /src
39-
// $request_dir_path_no_start = ltrim($request_dir_path, $start_dir_path); // tutorial, "", ""
40-
41-
// server
42-
// $server_name = $_SERVER['SERVER_NAME']; // fimik.com
43-
// $server_port = $_SERVER['SERVER_PORT']; // 80
44-
// if ($server_port == '80') {
45-
// $server_address = 'http://' . $server_name . $start_dir_path;
46-
// } else {
47-
// $server_address = 'http://' . $server_name . ':' . $server_port . $start_dir_path;
48-
// }
49-
5036
chdir('../');
5137

5238
// header
@@ -55,6 +41,7 @@
5541
$md = file_get_contents($doc_header_file_path);
5642
$Parsedown = new Parsedown();
5743
$html = $Parsedown->text($md);
44+
// add start dir path to the front
5845
$xml = new DOMDocument('1.0','UTF-8');
5946
$xml->loadHTML($html);
6047
foreach($xml->getElementsByTagName('a') as $link) {
@@ -82,6 +69,7 @@
8269
$md = file_get_contents($doc_ending_file_path);
8370
$Parsedown = new Parsedown();
8471
$html = $Parsedown->text($md);
72+
// add start dir path to the front
8573
$xml = new DOMDocument('1.0','UTF-8');
8674
$xml->loadHTML($html);
8775
foreach($xml->getElementsByTagName('a') as $link) {
@@ -121,6 +109,7 @@
121109
$md = file_get_contents($doc_footer_file_path);
122110
$Parsedown = new Parsedown();
123111
$html = $Parsedown->text($md);
112+
// add start dir path to the front
124113
$xml = new DOMDocument('1.0','UTF-8');
125114
$xml->loadHTML($html);
126115
foreach($xml->getElementsByTagName('a') as $link) {
@@ -139,7 +128,7 @@
139128
}
140129
}
141130
// main
142-
$request_uri_no_start = ltrim($request_uri, $start_dir_path); // tutorial/default.md, tutorial/, tutorial
131+
$request_uri_no_start = substr($request_uri, strlen($start_dir_path)); // tutorial/default.md, tutorial/, tutorial
143132
if ($request_uri_no_start == "") {
144133
$doc_main_file_path = "default.md";
145134
} elseif (substr($request_uri_no_start, -1) == "/") {
@@ -149,7 +138,6 @@
149138
} else {
150139
$doc_main_file_path = $request_uri_no_start . "/default.md";
151140
}
152-
// var_dump($doc_main_file_path);
153141
if (!file_exists($doc_main_file_path)) {
154142
$doc_main_file_path = "404.md";
155143
}
@@ -165,9 +153,9 @@
165153
$json = file_get_contents($meta_file_path);
166154
$meta = json_decode($json, true);
167155
}
168-
// var_dump($data);
169-
// echo getcwd();
170-
// echo PHP_EOL;
156+
// echo "<p>";
157+
// var_dump($request_uri_no_start);
158+
// echo "</p>";
171159
// var_dump(glob('*'));
172160
// echo PHP_EOL;
173161
// exit();
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)