Fossil SCM

In documentation search results, change URLs of the form "/doc/BRANCH/path" so that BRANCH is the branch name specified by the "doc-branch" setting.

drh 2016-08-30 00:49 trunk
Commit fa947eebfdcd78286e6593896bf81c2521664d7a
1 file changed +14 -2
+14 -2
--- src/search.c
+++ src/search.c
@@ -920,10 +920,11 @@
920920
unsigned int srchFlags, /* What to search over */
921921
int fDebug /* Extra debugging output */
922922
){
923923
Stmt q;
924924
int nRow = 0;
925
+ const char *zDocBr = 0; /* The branch of documentation to search */
925926
926927
srchFlags = search_restrict(srchFlags);
927928
if( srchFlags==0 ) return 0;
928929
search_sql_setup(g.db);
929930
add_content_sql_commands(g.db);
@@ -941,17 +942,28 @@
941942
" ORDER BY score DESC, date DESC;");
942943
while( db_step(&q)==SQLITE_ROW ){
943944
const char *zUrl = db_column_text(&q, 0);
944945
const char *zSnippet = db_column_text(&q, 1);
945946
const char *zLabel = db_column_text(&q, 2);
947
+ const char *zId = db_column_text(&q,4);
946948
if( nRow==0 ){
947949
@ <ol>
948950
}
949951
nRow++;
950
- @ <li><p><a href='%R%s(zUrl)'>%h(zLabel)</a>
952
+ if( strncmp(zUrl,"/doc/",5)==0 ){
953
+ /* Change the BRANCH in URLs like "/doc/BRANCH/path" into the
954
+ ** branch name specified by the doc-branch setting. */
955
+ int i;
956
+ if( zDocBr==0 ) zDocBr = db_get("doc-branch","trunk");
957
+ for(i=5; zUrl[i]; i++) if( zUrl[i]=='/' ){ i++; break; }
958
+ @ <li><p><a href='%R/doc/%T(zDocBr)/%T(zUrl+i)'>%h(zLabel)</a>
959
+ }else{
960
+ /* Non-"/doc/" URLs are delivered as is */
961
+ @ <li><p><a href='%R%T(zUrl)'>%h(zLabel)</a>
962
+ }
951963
if( fDebug ){
952
- @ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4)))
964
+ @ (%e(db_column_double(&q,3)), %s(zId))
953965
}
954966
@ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li>
955967
}
956968
db_finalize(&q);
957969
if( nRow ){
958970
--- src/search.c
+++ src/search.c
@@ -920,10 +920,11 @@
920 unsigned int srchFlags, /* What to search over */
921 int fDebug /* Extra debugging output */
922 ){
923 Stmt q;
924 int nRow = 0;
 
925
926 srchFlags = search_restrict(srchFlags);
927 if( srchFlags==0 ) return 0;
928 search_sql_setup(g.db);
929 add_content_sql_commands(g.db);
@@ -941,17 +942,28 @@
941 " ORDER BY score DESC, date DESC;");
942 while( db_step(&q)==SQLITE_ROW ){
943 const char *zUrl = db_column_text(&q, 0);
944 const char *zSnippet = db_column_text(&q, 1);
945 const char *zLabel = db_column_text(&q, 2);
 
946 if( nRow==0 ){
947 @ <ol>
948 }
949 nRow++;
950 @ <li><p><a href='%R%s(zUrl)'>%h(zLabel)</a>
 
 
 
 
 
 
 
 
 
 
951 if( fDebug ){
952 @ (%e(db_column_double(&q,3)), %s(db_column_text(&q,4)))
953 }
954 @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li>
955 }
956 db_finalize(&q);
957 if( nRow ){
958
--- src/search.c
+++ src/search.c
@@ -920,10 +920,11 @@
920 unsigned int srchFlags, /* What to search over */
921 int fDebug /* Extra debugging output */
922 ){
923 Stmt q;
924 int nRow = 0;
925 const char *zDocBr = 0; /* The branch of documentation to search */
926
927 srchFlags = search_restrict(srchFlags);
928 if( srchFlags==0 ) return 0;
929 search_sql_setup(g.db);
930 add_content_sql_commands(g.db);
@@ -941,17 +942,28 @@
942 " ORDER BY score DESC, date DESC;");
943 while( db_step(&q)==SQLITE_ROW ){
944 const char *zUrl = db_column_text(&q, 0);
945 const char *zSnippet = db_column_text(&q, 1);
946 const char *zLabel = db_column_text(&q, 2);
947 const char *zId = db_column_text(&q,4);
948 if( nRow==0 ){
949 @ <ol>
950 }
951 nRow++;
952 if( strncmp(zUrl,"/doc/",5)==0 ){
953 /* Change the BRANCH in URLs like "/doc/BRANCH/path" into the
954 ** branch name specified by the doc-branch setting. */
955 int i;
956 if( zDocBr==0 ) zDocBr = db_get("doc-branch","trunk");
957 for(i=5; zUrl[i]; i++) if( zUrl[i]=='/' ){ i++; break; }
958 @ <li><p><a href='%R/doc/%T(zDocBr)/%T(zUrl+i)'>%h(zLabel)</a>
959 }else{
960 /* Non-"/doc/" URLs are delivered as is */
961 @ <li><p><a href='%R%T(zUrl)'>%h(zLabel)</a>
962 }
963 if( fDebug ){
964 @ (%e(db_column_double(&q,3)), %s(zId))
965 }
966 @ <br /><span class='snippet'>%z(cleanSnippet(zSnippet))</span></li>
967 }
968 db_finalize(&q);
969 if( nRow ){
970

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button