mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
fix: zim dictionary auto refresh logic
fix <meta http-equiv="Refresh"
This commit is contained in:
parent
b02b6f9bcb
commit
f730a4aabc
|
@ -167,10 +167,17 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
|
||||||
|
|
||||||
if(req.url().scheme()=="gdlookup"){
|
if(req.url().scheme()=="gdlookup"){
|
||||||
QString path=url.path();
|
QString path=url.path();
|
||||||
if(!path.isEmpty()){
|
if( !path.isEmpty() )
|
||||||
Utils::Url::addQueryItem(url,"word",path.mid(1));
|
{
|
||||||
url.setPath("");
|
url.setPath( "" );
|
||||||
Utils::Url::addQueryItem(url,"group","1");
|
QByteArray referer = req.rawHeader( "Referer" );
|
||||||
|
QUrl refererUrl = QUrl::fromEncoded( referer );
|
||||||
|
|
||||||
|
Utils::Url::addQueryItem( url, "word", path.mid( 1 ) );
|
||||||
|
if( Utils::Url::hasQueryItem( refererUrl, "group" ) )
|
||||||
|
{
|
||||||
|
Utils::Url::addQueryItem( url, "group", Utils::Url::queryItemValue( refererUrl, "group" ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +318,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
|
||||||
|
|
||||||
bool ignoreDiacritics = Utils::Url::queryItemValue( url, "ignore_diacritics" ) == "1";
|
bool ignoreDiacritics = Utils::Url::queryItemValue( url, "ignore_diacritics" ) == "1";
|
||||||
|
|
||||||
if ( groupIsValid && phrase.isValid() ) // Require group and phrase to be passed
|
if ( phrase.isValid() ) // Require group and phrase to be passed
|
||||||
return articleMaker.makeDefinitionFor( phrase, group, contexts, mutedDicts, QStringList(), ignoreDiacritics );
|
return articleMaker.makeDefinitionFor( phrase, group, contexts, mutedDicts, QStringList(), ignoreDiacritics );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
106
zim.cc
106
zim.cc
|
@ -874,54 +874,35 @@ string ZimDictionary::convert( const string & in )
|
||||||
for( int i = list.size(); i < 5; i++ )
|
for( int i = list.size(); i < 5; i++ )
|
||||||
list.append( QString() );
|
list.append( QString() );
|
||||||
|
|
||||||
|
QString formatTag;
|
||||||
QString tag = list[3]; // a url, ex: Precambrian_Chaotian.html
|
QString tag = list[3]; // a url, ex: Precambrian_Chaotian.html
|
||||||
if ( !list[4].isEmpty() ) // a title, ex: title="Precambrian/Chaotian"
|
if ( !list[4].isEmpty() ) // a title, ex: title="Precambrian/Chaotian"
|
||||||
tag = list[4].split("\"")[1];
|
|
||||||
|
|
||||||
// Check type of links inside articles
|
|
||||||
if( linksType == UNKNOWN && tag.indexOf( '/' ) >= 0 )
|
|
||||||
{
|
{
|
||||||
QString word = QUrl::fromPercentEncoding( tag.toLatin1() );
|
tag = list[4];
|
||||||
QRegularExpression htmlRx( "\\.(s|)htm(l|)$", QRegularExpression::CaseInsensitiveOption );
|
formatTag=tag.split("\"")[1];
|
||||||
word.remove( htmlRx ).
|
}
|
||||||
replace( "_", " " );
|
else{
|
||||||
|
//tag from list[3]
|
||||||
vector< WordArticleLink > links;
|
formatTag = tag;//tag.replace(QRegularExpression("[\\.\\/]"),"-");
|
||||||
links = findArticles( gd::toWString( word ) );
|
|
||||||
|
|
||||||
if( !links.empty() )
|
|
||||||
{
|
|
||||||
linksType = SLASH;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
word.remove( QRegularExpression(".*/") );
|
|
||||||
links = findArticles( gd::toWString( word ) );
|
|
||||||
if( !links.empty() )
|
|
||||||
{
|
|
||||||
linksType = NO_SLASH;
|
|
||||||
links.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( linksType == SLASH || linksType == UNKNOWN )
|
formatTag.replace(QRegularExpression("[\\.\\/]"),"");
|
||||||
{
|
|
||||||
tag.remove( QRegularExpression( "\\.(s|)htm(l|)$", QRegularExpression::PatternOption::CaseInsensitiveOption ) ).
|
vector< WordArticleLink > links;
|
||||||
replace( "_", "%20" ).
|
links = findArticles( gd::toWString( formatTag ) );
|
||||||
prepend( "<a href=\"gdlookup://localhost/" ).
|
|
||||||
append( "\" " + list[4] + ">" );
|
|
||||||
|
QString urlLink = match.captured();
|
||||||
|
QString replacedLink ;
|
||||||
|
|
||||||
|
if(!links.empty()){
|
||||||
|
replacedLink = urlLink.replace(tag,"gdlookup://localhost/"+formatTag);
|
||||||
}
|
}
|
||||||
else
|
else{
|
||||||
{
|
replacedLink = urlLink.replace(tag,"bres://localhost/"+formatTag);
|
||||||
tag.remove( QRegularExpression(".*/") ).
|
|
||||||
remove( QRegularExpression( "\\.(s|)htm(l|)$", QRegularExpression::PatternOption::CaseInsensitiveOption ) ).
|
|
||||||
replace( "_", "%20" ).
|
|
||||||
prepend( "<a href=\"gdlookup://localhost/" ).
|
|
||||||
append( "\" " + list[4] + ">" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newText += tag;
|
newText += replacedLink;
|
||||||
}
|
}
|
||||||
if( pos )
|
if( pos )
|
||||||
{
|
{
|
||||||
|
@ -1648,25 +1629,43 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
|| ( mimetype == 0xFFFF && df.isArticleMime( redirected_mime ) ) ) ) )
|
|| ( mimetype == 0xFFFF && df.isArticleMime( redirected_mime ) ) ) ) )
|
||||||
{
|
{
|
||||||
wstring word;
|
wstring word;
|
||||||
if( !title.empty() )
|
|
||||||
word = Utf8::decode( title );
|
|
||||||
else
|
|
||||||
word = Utf8::decode( url );
|
|
||||||
|
|
||||||
if( df.isArticleMime( mimetype )
|
if( df.isArticleMime( mimetype )
|
||||||
|| ( mimetype == 0xFFFF && df.isArticleMime( redirected_mime ) ) )
|
|| ( mimetype == 0xFFFF && df.isArticleMime( redirected_mime ) ) )
|
||||||
{
|
{
|
||||||
if( maxHeadwordsToExpand && zh.articleCount >= maxHeadwordsToExpand )
|
if( maxHeadwordsToExpand && zh.articleCount >= maxHeadwordsToExpand )
|
||||||
indexedWords.addSingleWord( word, n );
|
{
|
||||||
|
if( !title.empty() )
|
||||||
|
{
|
||||||
|
word = Utf8::decode( title );
|
||||||
|
indexedWords.addSingleWord( word, n );
|
||||||
|
}
|
||||||
|
if( !url.empty() )
|
||||||
|
{
|
||||||
|
auto formatedUrl = QString::fromStdString( url ).replace( QRegularExpression( "[\\.\\/]" ), "" );
|
||||||
|
indexedWords.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n );
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
indexedWords.addWord( word, n );
|
{
|
||||||
|
if( !title.empty() )
|
||||||
|
{
|
||||||
|
word = Utf8::decode( title );
|
||||||
|
indexedWords.addWord( word, n );
|
||||||
|
}
|
||||||
|
if( !url.empty() )
|
||||||
|
{
|
||||||
|
auto formatedUrl = QString::fromStdString( url ).replace( QRegularExpression( "[\\.\\/]" ), "" );
|
||||||
|
indexedWords.addWord( Utf8::decode( formatedUrl.toStdString() ), n );
|
||||||
|
}
|
||||||
|
}
|
||||||
wordCount++;
|
wordCount++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
url.insert( url.begin(), '/' );
|
// url.insert( url.begin(), '/' );
|
||||||
url.insert( url.begin(), nameSpace );
|
// url.insert( url.begin(), nameSpace );
|
||||||
indexedResources.addSingleWord( Utf8::decode( url ), n );
|
auto formatedUrl = QString::fromStdString(url).replace(QRegularExpression("[\\.\\/]"),"");
|
||||||
|
indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1702,9 +1701,10 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
url.insert( url.begin(), '/' );
|
// url.insert( url.begin(), '/' );
|
||||||
url.insert( url.begin(), nameSpace );
|
// url.insert( url.begin(), nameSpace );
|
||||||
indexedResources.addSingleWord( Utf8::decode( url ), n );
|
auto formatedUrl = QString::fromStdString(url).replace(QRegularExpression("[\\.\\/]"),"");
|
||||||
|
indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue